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.

Karma can't find unit tests in Angular 2 project #499

Closed

Description

@danoleary

I have created an Angular 2 project with unit tests. However, when I run 'npm test' I get the following result even though an example test is included with the counter component.

Executed 0 of 0 ERROR (0.003 secs / 0 secs)

Activity

  1. SteveSandersonMS commented on Dec 8, 2016

    @SteveSandersonMS
    Member

    Can you give repro steps? For example, I just did the following:

    mkdir myproject
    cd myproject
    yo aspnetcore-spa
    npm test
    

    ... and get the expected result: Executed 2 of 2 SUCCESS

    If those steps don't produce the same result on your machine, can you describe your environment in some more detail that might make it possible to reproduce the issue? Thanks!

  2. danoleary commented on Dec 8, 2016

    @danoleary
    Author

    I followed those same steps, with the following options:
    Framework? Angular 2 Do you want to include unit tests? Y Your project name? myproject

    OS: Windows 10
    npm: 4.0.3
    node: v6.9.2

    Are there any other details that would be helpful?

  3. Krishna-teja commented on Dec 25, 2016

    @Krishna-teja

    @SteveSandersonMS I am also receiving the same error.

    OS: Windows 10
    npm: 3.10.9
    node: v6.9.2

  4. MarkPieszak commented on Dec 25, 2016

    @MarkPieszak
    Contributor

    Can you guys upgrade to the latest node 7.x and give it a shot by any chance? @Krishna-teja @danoleary

    Also if you can, do a clean npm install as well.

  5. Krishna-teja commented on Dec 25, 2016

    @Krishna-teja

    @MarkPieszak Doing a clean install and upgrading to node 7.x worked. Thanks!

  6. MarkPieszak commented on Dec 25, 2016

    @MarkPieszak
    Contributor

    great, glad to hear it!

  7. craigktreasure commented on Jan 3, 2017

    @craigktreasure

    Is there a way to get this to work on Node 6 LTS?

  8. SteveSandersonMS commented on Jan 3, 2017

    @SteveSandersonMS
    Member

    @craigktreasure Have you confirmed that it really is an issue with Node 6? I know @Krishna-teja worked around it by installing Node 7, but maybe his Node 6 installation was just broken in some way.

    If it really is an issue in Node 6, can you say what specifically about Node 6 causes the incompatibility?

  9. craigktreasure commented on Jan 3, 2017

    @craigktreasure

    @SteveSandersonMS I see the same behavior on two different Windows machines. Unfortunately, i don't know what causes the incompatibility right now. I assumed (and hoped) that the suggestion to try Node 7 meant that someone had a hint as to what it might be.

  10. MarkPieszak commented on Jan 3, 2017

    @MarkPieszak
    Contributor

    Unfortunately I don't know exactly what's causing it in 6, but I'd imagine in a minor release update within 6.x that it might be fixed. Fortunately on the dev-side using 7.x is safe enough, so whatever is happening there fixes the issue.

  11. craigktreasure commented on Jan 3, 2017

    @craigktreasure

    I'm running the latest patch release of 6 (6.9.2), so i don't believe it has been fixed. Not in a released build anyway.

  12. SteveSandersonMS commented on Jan 3, 2017

    @SteveSandersonMS
    Member

    I tracked it down. As suspected, it's nothing to do with your Node version. It's to do with your Chrome version. Newer versions of Chrome are stricter about the MIME types on script files, and the Karma config didn't specify a MIME type for .ts files.

    To fix it, add the following to your karma.conf.js:

    mime: { 'application/javascript': ['ts','tsx'] }
    

    ... as in this commit: 8c456aa

  13. craigktreasure commented on Jan 3, 2017

    @craigktreasure

    @SteveSandersonMS Great news since i just tried it with Node 7 and it still didn't work. Thanks so much! Any insights into how you discovered this?

  14. SteveSandersonMS commented on Jan 3, 2017

    @SteveSandersonMS
    Member

    I just opened the Chrome developer tools in the Karma window and saw a nice clear error message saying what the problem was :)

  15. craigktreasure commented on Jan 3, 2017

    @craigktreasure

    Odd. That was the first place i looked and it didn't say anything was wrong in the console or in the requests. Regardless, thanks for your help.

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