开发者

Why would false not be defined in jasmine?

开发者 https://www.devze.com 2023-01-31 23:42 出处:网络
I\'m using jasmine in conjunctio开发者_JAVA百科n to Js-test-driver using an adapter to connect them both.

I'm using jasmine in conjunctio开发者_JAVA百科n to Js-test-driver using an adapter to connect them both.

I've got the following test case:

describe("Undefined false", function(){
    beforeEach(function(){
        var undefFalse = false;
    });

    it("should return a defined value", function(){
        expect(this.undefFalse).toBeDefined();
    });

    it("should return false", function(){
        expect(this.undefFalse).toBeFalsy();
    });
});

Whereas the second test succeeds as expected, the first fails with the following error:

Undefined false test.test that it should return a defined value failed (0,00 ms): AssertError: Expected undefined to be defined.

Why is it that false should be undefined?


I don't know much about jasmine but this:

var undefFalse = false; // local variable

this.undefFalse; // property of an object(?)

will obviously not work.

Make sure to either get rid of the this. in the asserts, or set undefFalse on the correct object.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号