Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
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

Closed

Description

@SteveSandersonMS

Original request was #87, with comments:

@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

Activity

  1. EduardTheThird commented on Oct 6, 2016

    @EduardTheThird

    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!

    karmaoutput

    Screenshot of the package.json that was used:

    karmapackage

  2. MarkPieszak commented on Oct 6, 2016

    @MarkPieszak
    Contributor

    @EduardTheThird Do you have noResolve: false in your karma.config.js?

  3. EduardTheThird commented on Oct 7, 2016

    @EduardTheThird

    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:

    karmaconf

    For reference, this is the unit test spec used, both Jasmine "expect" and Chai "assert" markup returns the same error:

    test

    testassert

    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.

  4. SteveSandersonMS commented on Nov 10, 2016

    @SteveSandersonMS
    MemberAuthor

    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.

  5. MarkPieszak commented on Nov 11, 2016

    @MarkPieszak
    Contributor

    @SteveSandersonMS Let me take a look tomorrow morning and I'll get back to you!

  6. EduardTheThird commented on Nov 11, 2016

    @EduardTheThird

    I can confirm that unit tests are working now! Thank you @SteveSandersonMS 😸

  7. MarkPieszak commented on Nov 17, 2016

    @MarkPieszak
    Contributor

    @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. 👍 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions