I noticed that if I write the expect expect(null).toBeDefined();
, the test will be pass because Jasmine considers that null is an object defined but without any value.
My question is if there is a matcher that evaluates whether the object is different from both undefined
and null
.
Just use .toEqual()
:
expect(context).not.toEqual(null);
In Javascript undefined == null
is true
, so this test will exclude both undefined
and null
.