Skip to content
Advertisement

What is the alternative for “toNotEqual” in Jasmine?

I am trying to write Unit Test in Jasmine and in my code, I am comparing two objects for inequality.

I am using following code to do it:

expect(obj1).toNotEqual(obj2)

But getting following error:

TypeError: expect(…).toNotEqual is not a function

Can anyone please suggest how to resolve this?

Advertisement

Answer

It could have been more useful if you specified the Jasmine Version you are using.

But anyway answer to your question is .. all Jasmine versions 1.3,2.0,2.1 to 2.5 don’t support toNotEqual and in case you want to check inequality you have to chain NOT to expect before the matches.

Use not.toEqual for check inequality of object.

expect(obj1).not.toEqual(obj2)

toEqual matches deep equality. It does a recursive search through the objects to determine whether the values for their keys are equivalent.

toBe matches primitive types.

Advertisement