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?
use expect(JSON.stringify(controlStrore)).toEqual(JSON.stringify(liveStore))
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())
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With