Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest Test "Compared values have no visual difference."

I'm doing a comparison between two objects that are quite complex and attempting to use the .toEqual method in expect.

Here is my test:

it('check if stepGroups data in controlData matches data in liveData', () =>    {
    var controlStore = data.controlStore
    var liveStore
    return getData().then(result => {
        liveStore = new Store()
        liveStore.loadData(JSON.parse(result))
        expect(controlStore).toEqual(liveStore)  
    })
})

I did a diff between the expected and the the received output and they both appear to be the same. What would still be causing this test to fail? I was reading up on pretty-format (https://github.com/facebook/jest/issues/1622). Have you run into similar situations?

like image 495
Stefan H. Avatar asked Mar 21 '17 13:03

Stefan H.


3 Answers

use expect(JSON.stringify(controlStrore)).toEqual(JSON.stringify(liveStore))

like image 175
user2584621 Avatar answered Nov 02 '22 07:11

user2584621


In your code sample you are comparing two instances of Store, which encapsulate some data. Thus even if data (result json in your case) is the same, it doesn't necessarily imply that both container instances can be considered equal.

It should be possible to do something like expect(controlStore.getState()).toEqual(liveStore.getState()).

like image 12
eur00t Avatar answered Nov 02 '22 06:11

eur00t


You probably trying to set a method via a lambda-function in your Store class. So jest is trying to compare to different functions, which were generated separately each time you do new Store(). As a result it rises an error, though it cant display difference, it just cant print functions.

like image 3
Дмитрий Матушкин Avatar answered Nov 02 '22 05:11

Дмитрий Матушкин