【发布时间】:2015-01-26 10:39:03
【问题描述】:
我正在使用量角器进行 jasine 测试,但我不确定 expect 是如何工作的。我希望茉莉花给我一个失败,因为我显然有一个失败的期望。但它没有。
我使用使用 Jasmine2 的 grunt-protractor-runner 1.2.1。
我有这个测试用例:
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 都会立即显示在日志中,并且在此之前。 所以看起来在处理期望函数之前调用了 done 。这可能是什么原因? expect() 是异步的吗?
现在我只使用“应该”库。这就像一个魅力。我还是想知道我做错了什么。
【问题讨论】:
标签: node.js jasmine protractor