3

For some reason jasmine's...

expect({}).toEqual([]);

is reporting true (but they are different types). How do I do this check with jasmine?

Exitos
  • 29,230
  • 38
  • 123
  • 178
  • If they are both empty, they will always return true. This is what I suppose it does. Maybe if you populate the two arrays with equal data will fix that. – ascx May 12 '15 at 07:25
  • That seems normal. Have a look at this : http://jasmine.github.io/2.0/custom_equality.html – Deblaton Jean-Philippe May 12 '15 at 07:25
  • 1
    @Socialz Do you have a link to a documentation of `toEqual` supporting what you're saying ? – Denys Séguret May 12 '15 at 07:27
  • I just tried `expect(({}).toString()).toEqual(([]).toString())`, and it works in Chrome, but I'm not sure that it's works in all browsers. – azaviruha May 12 '15 at 07:34
  • It seems, that you need to add more context for the question. Is your task only to force Jasmine to throw alert only for `expect({}).toEqual([]);` or it's a part of more general case? – azaviruha May 12 '15 at 08:08
  • Guys this is using Jasmine-Node! So are we saying this doesn't happen in Chrome? – Exitos May 12 '15 at 09:06

3 Answers3

1

You can move the equality check within the expect clause:

a = {}
b = []
expect(a === b).toBeTruthy();
Cristik
  • 30,989
  • 25
  • 91
  • 127
0

With lodash you can do this:

expect( _.isEqual(a, b) ).toBe( false );

azaviruha
  • 896
  • 1
  • 7
  • 14
0

Have a look at the JasmineMatchers project. It adds matchers like toBeEmptyObject and toBeArray and toBeEmptyArray and many others.

johnmcase
  • 1,769
  • 2
  • 16
  • 27