在Grunt上运行的Jasmine无法找到异步功能

时间:2014-04-23 13:26:23

标签: javascript gruntjs

出于某种原因,当我从Grunt运行时,Jasmine中的异步函数(等待,等待,运行)不可用。

在Grunt:

jasmine:{
    pivotal:{
        src: 'src/**/*.js',
        options:{
            specs: 'spec/**/*.spec.js'
        }
    }
}

在Jasmine规范中:

describe('jasmine', function(){
    it("should find 'waits'", function(){
        waits(1000);
    });
    it("should find 'waitsFor'", function(){
        waitsFor(function(){}, 1000);
    });
    it("should find 'runs'", function(){
        runs(function(){});
    });
})

Jasmine输出:

 jasmine
   × should find 'waits'
     ReferenceError: Can't find variable: waits in file:///G:/Projects/myproj/spec/test.spec.js (line 3) (1)
   × should find 'waitsFor'
     ReferenceError: Can't find variable: waitsFor in file:///G:/Projects/myproj/spec/test.spec.js (line 6) (1)
   × should find 'runs'
     ReferenceError: Can't find variable: runs in file:///G:/Projects/myproj/spec/test.spec.js (line 9) (1)

我错过了什么吗?

1 个答案:

答案 0 :(得分:5)

结果我习惯使用Jasmine 1.3,而grunt使用的版本是2.0。语法在2.0中已更改,测试需要根据http://jasmine.github.io/2.0/introduction.html

上的文档编写