docs-v7 icon indicating copy to clipboard operation
docs-v7 copied to clipboard

Document testing Angular components with TestBed

Open vakrilov opened this issue 5 years ago • 6 comments

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:

  1. Add testing to your project. Probably just point to https://docs.nativescript.org/tooling/testing
  2. Add TestBed.
    1. Create a file with TestBed init code. Example: https://github.com/NativeScript/nativescript-angular/blob/master/tests/app/tests/test-main.ts
    2. Include it in karma.config. Example: https://github.com/NativeScript/nativescript-angular/blob/master/tests/karma.conf.js#L16
  3. 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
  4. Point to some external in depth article of using TestBed, like https://angular.io/guide/testing
  5. Talk about NativeScript specific limitations and differences if there are such.

vakrilov avatar Sep 25 '18 12:09 vakrilov

I'm digging this now and still found out no documentation has been made out of yet. Any plans for this?

coderaven avatar May 27 '19 09:05 coderaven

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.

milesgranger avatar Jul 23 '19 03:07 milesgranger

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

gsavchenko avatar Jul 24 '19 19:07 gsavchenko

you can update the docs here. It will then appear online.

You'll find a sample here: https://github.com/hypery2k/tns_testbed_sample

hypery2k avatar Oct 31 '19 16:10 hypery2k

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: (?)

gsavchenko avatar Oct 31 '19 17:10 gsavchenko

you're right, I missed to checkin karma.conf.js

I fixed that and proposed a PR for the docs

hypery2k avatar Nov 01 '19 03:11 hypery2k