javascript - What's the difference between '.toMatchObject' and 'objectContaining' -


i have written following test:

it('can decrement current step', function () {     expect(reducer(teststate, { type: 'goto_previous_step' })).tomatchobject({ currentstep: 4 }); });  it('can decrement current step v2', function () {     expect(reducer(teststate, { type: 'goto_previous_step' })).toequal(expect.objectcontaining({ currentstep: 4 })); }); 

both of them seem pass test, there difference between them? there performance impact between them?

my thinking expect.objectcontaining (and other matchers it) can used instead of literal values inside "object" pass other matchers.

this example docs:

test('onpress gets called right thing', () => {   const onpress = jest.fn();   simulatepresses(onpress);   expect(onpress).tobecalledwith(expect.objectcontaining({     x: expect.any(number),     y: expect.any(number),   })); }); 

so, while seem same thing in example, expect.* ones useful in other way.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -