MoeSattler
MoeSattler

Reputation: 6894

Expect not fully working in Jasmine

I am running a jasine test with protractor, and I am not sure how expect is working. I expect jasmine to give me a failure since I am obviously have a failed expectation. It does not though.

I use grunt-protractor-runner 1.2.1 which uses Jasmine2.

I have this test case:

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);
    });
});

Any idea what I am missing here? Am I missing some async functions? One thing I noticed is, when I comment out 'done()', some seconds after everything already happened the logs start showing me one of these for every iteration calling 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'.

All the console.logs are showed immediately in the logs and way before this. So it looks like done is called before the expect function is processed. What can be the reason for that? is expect() async?

For now I am just using the "should" library. That works like a charme. Still I would like to know what I did wrong.

Upvotes: 4

Views: 631

Answers (1)

hankduan
hankduan

Reputation: 6034

You're missing it. See http://jasmine.github.io/2.0/introduction.html for documentations on jasmine.

You might also need to change your timeout: https://github.com/angular/protractor/blob/master/docs/timeouts.md#timeouts-from-jasmine

Upvotes: 1

Related Questions