0
//spec

it('check process data to see if it returns correct JSON object', function() {

var dataExpected = [];

    dataExpected.push({
        image : "https://katmou.files.wordpress.com/2011/11/blade_runner.jpeg",
        title : "Harrison",
        id : 1

    });

    expect(dataAfter).toEqual(dataExpected);
});

error:

[ERROR] :  .  THERE WERE FAILURES!
[ERROR] :  .  ============================================================
[ERROR] :  .  Recap of failing specs:
[ERROR] :  .  ------------------------------------------------------------
[ERROR] :  .  viewP controller check process data to see if it returns correct JSON object. - Expected [ { image : 'https://katmou.files.wordpress.com/2011/11/blade_runner.jpeg', title : 'Harrison', id : '1' } ] to equal [ { image : 'https://katmou.files.wordpress.com/2011/11/blade_runner.jpeg', title : 'Harrison', id : 1 } ].

The data after is identical to what is expected and it is still failing, why?

Cheers.

user3754111
  • 859
  • 1
  • 10
  • 20

2 Answers2

1

You are expecting the id property to be 1, but in the results it is '1'.

rosscj2533
  • 9,195
  • 7
  • 39
  • 56
0

As from the Jasmine 2.0 Doc http://jasmine.github.io/2.0/introduction.html the .toEqual should work for object, but you are passing an array with one object, so it may be different. Are you sure that dataAfter is declared the same way?(an obj inside an array)

A different solution could be compare that two array passing them as string with JSON.stringify(). See: Object comparison in JavaScript

Community
  • 1
  • 1
stefoonk
  • 1
  • 1