我正在使用量角器进行jasine测试,我不确定预期是如何工作的。我希望茉莉花给我一个失败,因为我显然有一个失败的期望。但事实并非如此。
我使用grunt-protractor-runner 1.2.1,它使用Jasmine2。
我有这个测试用例:
var validateObject = function(object) {
expect('1.0').toEqual('1.0'); //no error
//expect('1.1').toEqual('1.0'); //error
console.log(object['property']); //1.0
console.log(object['property'] === '1.0'); //true
console.log(typeof object['property']); //string
/*PROBLEM STARTS HERE*/
expect(object['property']).toEqual('1.0'); //no error
expect(object['property']).toEqual('1.1'); //no error
};
var readSomething = function(done) {
fs.createReadStream('folder + fileName')
.pipe(operation.Parse())
.on('entry', function(file) {
validateObject(file);
.on('end', function(){
done();
});
};
describe('test this', function () {
it("stuff", function (done) {
/*lots of stuff happening*/
expect('asd').toEqual('asd'); //no error
//expect('asd').toEqual('asds'); //error
readSomething(done);
});
});
知道我在这里缺少什么吗?我错过了一些异步功能吗? 我注意到的一件事是,当我注释掉'done()'时,在所有事情发生后几秒钟,日志开始向我展示调用validateObject的每次迭代中的一个:
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
The last active task was:
unknown
F
Failures:
1) ----Bulkd Process----- testing the whole bulk process
Message:
Expected '1.0' to equal '1.1'.
所有的console.logs都会立即显示在日志和方式之前。 因此看起来在处理expect函数之前调用done。可能是什么原因?期待()async?
现在我只是使用“应该”库。这就像一个魅力。我仍然想知道我做错了什么。
答案 0 :(得分:1)