jasmine-node says "0 tests" when there *are* tests
Asked Answered
U

4

14

I expect this to say "1 test", but it says "0 tests". Any idea why? This is on OS X.

$ jasmine-node --verbose my.spec.js
undefined

Finished in 0.001 seconds
0 tests, 0 assertions, 0 failures, 0 skipped

$ cat my.spec.js
describe("bar", function() {
  it("works", function() {
    expect("foo").toEqual("foo");
  });
});

$ jasmine-node --version
1.11.0  
$ npm --version
1.3.5  
$ node -v
v0.4.12

Even if I try to create a syntax error I get the same output:

$ cat my.spec.js
it(
$ jasmine-node --verbose --captureExceptions my.spec.js
undefined

Finished in 0.001 seconds
0 tests, 0 assertions, 0 failures, 0 skipped

But if I try to specify a file that doesn't exist, it complains:

$ jasmine-node no.spec.js
File: /tmp/no.spec.js is missing.
Unfolded answered 10/8, 2013 at 14:32 Comment(1)
Added "describe" back in my spec, above, to rule that out as a source of errors. I get the same "0 tests" result even with it, I'm afraid.Unfolded
C
1

You should upgrade to the latest version of nodejs (currently 0.10.15)

Cuyp answered 10/8, 2013 at 14:53 Comment(9)
Alas, with your exact spec and your exact line to run it, I still get the exact same output.Unfolded
Why are you running node 0.4? That's a really old version. We are up to 0.10 and 0.4 is unsupportedCuyp
Exactly what I wanted to ask!Anastasio
@nirk Now we're talking. Will try updating Node and see if that helps. Thanks!Unfolded
Updated Node to 0.10.15 and now everything works. @nirk, thank you! I'm not very familiar with the world of node, so I specified versions in the hope of feedback like yours. If you write it as an answer I'll mark it as accepted.Unfolded
@Anastasio the --matchall is needed if you don't name the file properly. For example, if your test file is test.js then jasmine will get confusedCuyp
Yes, but it has nothing to do with this particular question.Anastasio
@Anastasio it fails in the same way (0 tests ...). Though in this case, the issue stemmed from an old version of nodeCuyp
It fails the same way with, or without --matchall. You removed it from answer anyway. All fine.Anastasio
A
34

I also had this problem, it was that I didn't name the file correctly:

your specification files must be named as spec.js, spec.coffee or spec.litcoffee, which matches the regular expression /spec.(js|coffee|litcoffee)$/i; otherwise jasmine-node won't find them! For example, sampleSpecs.js is wrong, sampleSpec.js is right.

Source: https://github.com/mhevery/jasmine-node

Anergy answered 16/2, 2014 at 20:18 Comment(1)
thanks! that helped me to get jasmine-node running in c9.io ! my files were called .specs.js instead of .spec.jsSadism
C
1

You should upgrade to the latest version of nodejs (currently 0.10.15)

Cuyp answered 10/8, 2013 at 14:53 Comment(9)
Alas, with your exact spec and your exact line to run it, I still get the exact same output.Unfolded
Why are you running node 0.4? That's a really old version. We are up to 0.10 and 0.4 is unsupportedCuyp
Exactly what I wanted to ask!Anastasio
@nirk Now we're talking. Will try updating Node and see if that helps. Thanks!Unfolded
Updated Node to 0.10.15 and now everything works. @nirk, thank you! I'm not very familiar with the world of node, so I specified versions in the hope of feedback like yours. If you write it as an answer I'll mark it as accepted.Unfolded
@Anastasio the --matchall is needed if you don't name the file properly. For example, if your test file is test.js then jasmine will get confusedCuyp
Yes, but it has nothing to do with this particular question.Anastasio
@Anastasio it fails in the same way (0 tests ...). Though in this case, the issue stemmed from an old version of nodeCuyp
It fails the same way with, or without --matchall. You removed it from answer anyway. All fine.Anastasio
D
1

This problem is in the filename.In jasmine-node, the name of file should end with 'spec' *spec.js eg: helloWorldspec.js or abcspec.js To quote from documentation:

your specification files must be named as *spec.js, *spec.coffee or *spec.litcoffee, which matches the regular expression /spec.(js|coffee|litcoffee)$/i; otherwise jasmine-node won't find them! For example, sampleSpecs.js is wrong, sampleSpec.js is right.

Please read more here.

Dion answered 30/1, 2017 at 12:7 Comment(0)
A
0

Don't you miss describe?

describe("A suite", function() {
  it("contains spec with an expectation", function() {
    expect(true).toBe(true);
  });
});

Running:

c:\Temp>jasmine-node --verbose my.Spec.js

A suite
    contains spec with an expectation

Finished in 0.007 seconds
1 test, 1 assertion, 0 failures, 0 skipped

everything works fine.

Anastasio answered 10/8, 2013 at 14:44 Comment(4)
Actually it has different result. Without describe you get [Error: jasmine.Suite() required]Anastasio
If only – that would be helpful. I see the exact same output with or without the describe, sad to say.Unfolded
So problem is elsewhere. Your file is not even parsed. It's even possible that your naming confuse (outdated) parser. Try first to name file mySpec.js, then if doesn't work, update Node.Anastasio
@HenrikN I just verified that the test spec file must be of the name *.Spec.js or else it won't be parsed.Dorren

© 2022 - 2024 — McMap. All rights reserved.