简体   繁体   English

当*是*测试时,jasmine-node表示“0测试”

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

I expect this to say "1 test", but it says "0 tests". 我希望这会说“1次测试”,但它会说“0次测试”。 Any idea why? 知道为什么吗? This is on OS X. 这是在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; 您的规范文件必须命名为spec.jsspec.coffeespec.litcoffee ,它们与正则表达式/spec.(js|coffee|litcoffee)$/i匹配; otherwise jasmine-node won't find them! 否则jasmine-node将找不到它们! For example, sampleSpecs.js is wrong, sampleSpec.js is right. 例如,sampleSpecs.js是错误的,sampleSpec.js是对的。

Source: https://github.com/mhevery/jasmine-node 资料来源: 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: 这个问题在filename.In jasmine-node中,文件名应以'spec'* spec.js结尾,例如:helloWorldspec.js或abcspec.js引用文档:

your specification files must be named as *spec.js, *spec.coffee or *spec.litcoffee, which matches the regular expression /spec.(js|coffee|litcoffee)$/i; 您的规范文件必须命名为* spec.js,* spec.coffee或* spec.litcoffee,它与正则表达式/spec.(js|coffee|litcoffee)$/i匹配; otherwise jasmine-node won't find them! 否则jasmine-node将找不到它们! For example, sampleSpecs.js is wrong, sampleSpec.js is right. 例如,sampleSpecs.js是错误的,sampleSpec.js是对的。

Please read more here . 在这里阅读更多。

Don't you miss describe ? 不要错过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. 一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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