docs-v7
docs-v7 copied to clipboard
Document testing Angular components with TestBed
Please, tell us what's the problem?
- [ ] A typo
- [ ] Wrong documentation
- [ ] Improvement of existing article
- [x] Missing documentation
- [ ] New article needed
Please, tell us more details
Document using TestBed to test Angular components in NativeScript. Here are some important things that this article should cover:
- Add testing to your project. Probably just point to https://docs.nativescript.org/tooling/testing
- Add TestBed.
- Create a file with TestBed init code. Example: https://github.com/NativeScript/nativescript-angular/blob/master/tests/app/tests/test-main.ts
- Include it in karma.config. Example: https://github.com/NativeScript/nativescript-angular/blob/master/tests/karma.conf.js#L16
- Show how to use the helper methods from
nativescript-angular/testing
to write a test-suite. Example: https://github.com/NativeScript/nativescript-angular/blob/master/tests/app/tests/list-view-tests.ts - Point to some external in depth article of using TestBed, like https://angular.io/guide/testing
- Talk about NativeScript specific limitations and differences if there are such.
I'm digging this now and still found out no documentation has been made out of yet. Any plans for this?
I would much appreciate this as well. Being pretty green to Angular and NativeScript, I need to write tests.
When generating a new service for example ng generate service Foo
I should be able to have tns test <platform>
run the associated test(s) in foo.service.spec.ts
.
I've been trying for a few hours to get this to work, but suspect I'm doing something silly.
Hey just like @milesgranger I also need to write tests.
I have similarly spent the last month attempting to get it to work and think I must be doing something wrong because the tests on the nativescript-angular repo seem to be working. If you have been able to achieve this please checkout my Stack Overflow question. Thanks.
https://stackoverflow.com/questions/57186925/how-to-implement-unit-tests-in-nativescript-using-testbed-and-jasmine
you can update the docs here. It will then appear online.
You'll find a sample here: https://github.com/hypery2k/tns_testbed_sample
you can update the docs here. It will then appear online.
You'll find a sample here: https://github.com/hypery2k/tns_testbed_sample
Hey, thanks for your comment! I've attempted to run your testbed sample and at first I noticed that there is no karma conf so I ran tns test init
, selected jasmine
and then ran tns test android
and the test does not seem to pass for me with the following error:
NativeScript / 28 (9; Android SDK built for x86) Renderer E2E executes events inside NgZone when listen is called outside NgZone FAILED
Error: Can't resolve all parameters for ApplicationModule: (?).
error properties: Object({ originalStack: 'Error: Can't resolve all parameters for ApplicationModule: (?)
you're right, I missed to checkin karma.conf.js
I fixed that and proposed a PR for the docs