简体   繁体   中英

jasmine-node says “0 tests” when there *are* tests

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.

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

你应该升级到最新版本的nodejs (目前是0.10.15)

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM