use*_*322 22 javascript jasmine
我在源文件中有这个功能:
function gimmeANumber(){
var x = 4;
return x;
}
Run Code Online (Sandbox Code Playgroud)
从本教程中借鉴了一个规范
describe('Hello world', function() {
beforeEach(function() {
this.addMatchers({
toBeDivisibleByTwo: function() {
return (this.actual % 2) === 0;
}
});
});
it('is divisible by 2', function() {
expect(gimmeANumber()).toBeDivisibleByTwo();
});
});
Run Code Online (Sandbox Code Playgroud)
这是错误:
TypeError:undefined不是Object的函数.(file:/// home/n/foo/jasmine/jasmine-2.0.0/dist/spec/HelloWorldSpec.js ...)谢谢.
Eit*_*eer 37
自1.3以来,用于添加自定义匹配器的API已更改.您可以在此处查看更改.
以下是它现在的工作原理:
function gimmeANumber() {
var x = 4;
return x;
}
describe('Hello world', function () {
beforeEach(function () {
jasmine.addMatchers({
toBeDivisibleByTwo: function () {
return {
compare: function (actual, expected) {
return {
pass: (actual % 2) === 0
};
}
};
}
});
});
it('is divisible by 2', function () {
expect(gimmeANumber()).toBeDivisibleByTwo();
expect(5).not.toBeDivisibleByTwo();
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4840 次 |
| 最近记录: |