You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
In templates, add option to generate unit tests #304
@on3al commented:
These templates are extremely helpful for getting started, but I'm at a loss how to fit unit testing into this workflow. Could someone please look into adding a working sample of a unit test using jasmine/karma? A jasmine test page in addition to the index page on the home controller that updates as changes occur during development would be great.
@laskoviymishka commented:
Good point, this issue related to #9.
A jasmine test page in controller IMHO is not quite good, it better to run your tests from CLI via something like karma. But option to add unit tests should be presented in yo generator definetely
The karma-testing-example was extremely helpful in setting up unit tests, thank you.
This suggested workflow worked for us up until the move to TypeScript 2 and the move to the new TS Types implementation.
Karma does start, however, Jasmine's definitions can't be found, even though we added @types/jasmine and @types/karma-jasmine. Please could you provide some much needed guidance!
Thank you for the suggestion, I've added noResolve to karma.config.js and unfortunately, the same errors persisted. I've tried setting it to both true and false.
Please find below the karma.config.js, it is the same as the karma-testing-example:
For reference, this is the unit test spec used, both Jasmine "expect" and Chai "assert" markup returns the same error:
Did the way unit test's get setup change with Angular 2 final, as I suspect the "ReferenceError: exports is not defined" error might be the culprit.
This is now implemented. If you get the latest generator-aspnetcore-spa generator, then when you create an Angular 2 project, it will ask if you want to include tests. If you say yes, then once the project is created, you can run npm test to start the Karma test runner.
FEEDBACK REQUESTED
For anyone familiar with good unit test practices in Angular 2 (@MarkPieszak?), do the contents of ClientApp/app/components/counter/counter.component.spec.ts look good to you? Note that it uses the whole TestBed stuff from @angular/core/testing rather than the pure viewmodel class testing approach described earlier in this thread.
@SteveSandersonMS Sorry for the delay, been swamped, but everything looks great from this end! TestBed is indeed the ideal way to test a Component in a more realistic environment. 👍 💯
Activity
EduardTheThird commentedon Oct 6, 2016
Hi @SteveSandersonMS
The karma-testing-example was extremely helpful in setting up unit tests, thank you.
This suggested workflow worked for us up until the move to TypeScript 2 and the move to the new TS Types implementation.
Karma does start, however, Jasmine's definitions can't be found, even though we added @types/jasmine and @types/karma-jasmine. Please could you provide some much needed guidance!
Screenshot of the package.json that was used:
MarkPieszak commentedon Oct 6, 2016
@EduardTheThird Do you have
noResolve: falsein your karma.config.js?EduardTheThird commentedon Oct 7, 2016
Hi @MarkPieszak
Thank you for the suggestion, I've added noResolve to karma.config.js and unfortunately, the same errors persisted. I've tried setting it to both true and false.
Please find below the karma.config.js, it is the same as the karma-testing-example:
For reference, this is the unit test spec used, both Jasmine "expect" and Chai "assert" markup returns the same error:
Did the way unit test's get setup change with Angular 2 final, as I suspect the "ReferenceError: exports is not defined" error might be the culprit.
SteveSandersonMS commentedon Nov 10, 2016
This is now implemented. If you get the latest
generator-aspnetcore-spagenerator, then when you create an Angular 2 project, it will ask if you want to include tests. If you say yes, then once the project is created, you can runnpm testto start the Karma test runner.FEEDBACK REQUESTED
For anyone familiar with good unit test practices in Angular 2 (@MarkPieszak?), do the contents of
ClientApp/app/components/counter/counter.component.spec.tslook good to you? Note that it uses the wholeTestBedstuff from@angular/core/testingrather than the pure viewmodel class testing approach described earlier in this thread.MarkPieszak commentedon Nov 11, 2016
@SteveSandersonMS Let me take a look tomorrow morning and I'll get back to you!
EduardTheThird commentedon Nov 11, 2016
I can confirm that unit tests are working now! Thank you @SteveSandersonMS 😸
MarkPieszak commentedon Nov 17, 2016
@SteveSandersonMS Sorry for the delay, been swamped, but everything looks great from this end! TestBed is indeed the ideal way to test a Component in a more realistic environment. 👍 💯