【问题标题】:Expect not fully working in Jasmine预计不能在 Jasmine 中完全工作
【发布时间】: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


    【解决方案1】:

    你错过了it。有关 jasmine 的文档,请参阅 http://jasmine.github.io/2.0/introduction.html

    您可能还需要更改超时时间:https://github.com/angular/protractor/blob/master/docs/timeouts.md#timeouts-from-jasmine

    【讨论】:

    • 其实我正在使用它,由于我试图抽象我的问题集,我忘了在这里添加它。现在更新了。
    • 我有一个相当高的开始。而且由于它适用于 should.js 而不是 jasmines 预期,因此我不希望我的测试取决于预期速度。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-29
    • 1970-01-01
    • 1970-01-01
    • 2013-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多