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.
Henrik N
  • 15,786
  • 5
  • 82
  • 131
  • 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. – Henrik N Aug 10 '13 at 14:59

4 Answers4

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

Community
  • 1
  • 1
edi9999
  • 19,701
  • 13
  • 88
  • 127
1

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

Matthias
  • 13,607
  • 9
  • 44
  • 60
SheetJS
  • 22,470
  • 12
  • 65
  • 75
  • Alas, with your exact spec and your exact line to run it, I still get the exact same output. – Henrik N Aug 10 '13 at 14:57
  • 1
    Why are you running node 0.4? That's a *really old* version. We are up to 0.10 and 0.4 is unsupported – SheetJS Aug 10 '13 at 14:59
  • Exactly what I wanted to ask! – Nenad Aug 10 '13 at 15:00
  • @nirk Now we're talking. Will try updating Node and see if that helps. Thanks! – Henrik N Aug 10 '13 at 15:00
  • 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. – Henrik N Aug 10 '13 at 15:10
  • 6
    @Nenad 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 confused – SheetJS Aug 10 '13 at 15:14
  • Yes, but it has nothing to do with this particular question. – Nenad Aug 10 '13 at 15:14
  • @Nenad it fails in the same way (0 tests ...). Though in this case, the issue stemmed from an old version of node – SheetJS Aug 10 '13 at 15:15
  • It fails the same way with, or without --matchall. You removed it from answer anyway. All fine. – Nenad Aug 10 '13 at 15:16
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.

hassan khademi
  • 1,156
  • 12
  • 14
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.

Nenad
  • 24,809
  • 11
  • 75
  • 93
  • Actually it has different result. Without describe you get [Error: jasmine.Suite() required] – Nenad Aug 10 '13 at 14:54
  • If only – that would be helpful. I see the exact same output with or without the describe, sad to say. – Henrik N Aug 10 '13 at 14:58
  • 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. – Nenad Aug 10 '13 at 15:01
  • @HenrikN I just verified that the test spec file must be of the name *.Spec.js or else it won't be parsed. – Bhargav Nanekalva Feb 04 '14 at 11:32