简体   繁体   中英

jasmine help, expect not working

//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.

您期望id属性为1 ,但结果为'1'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM