0

I'm using jasmine in conjunction 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?

LHM
  • 721
  • 12
  • 31
Eldros
  • 551
  • 1
  • 9
  • 28

1 Answers1

1

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.

Ivo Wetzel
  • 46,459
  • 16
  • 98
  • 112
  • Without the `this` on the second assertion, the second test `toBeFalsy` would fail. However, after reading your answer I changed the declaration to `this.undefFalse = false` and both test succeeded. My worry is that I might misuse `this` ... – Eldros Dec 22 '10 at 12:55
  • I don't think that you misuse `this` here, `this` refers to the test case in this case, so there shouldn't be any problem :) – Ivo Wetzel Dec 22 '10 at 15:26