Jest: Proposal of toMatchShapeOf

Created on 12 Oct 2017  路  1Comment  路  Source: facebook/jest

I'd like to have this in core lib

https://github.com/Dean177/jest-to-match-shape-of

When you have an object which has timestamp inside e.g.:

{
 name : 'Foo',
 surname: 'Bar',
 createdAt: 1507797749, <-- unix timestmap or other date format
}

https://facebook.github.io/jest/docs/en/expect.html#tomatchobjectobject will fail always while date value is moving. Would be great to have toMatchObjectShape. And it should go into child objects too.

Now I have to go around such cases by resetting result object (got from e.g. API endpoint) + I have to write expect cases for all time-based fields individually to check if a value was there before the reset.

Jest is great, I love it. Thanks for all who contribute 馃憤

Wontfix

Most helpful comment

expect(someObj).toEqual(expect.objectContaining({
    name: 'foo',
    surname: 'bar',
    createdAt: expect.any(Number),
}));

or

expect(someObj).toEqual({
    name: 'foo',
    surname: 'bar',
    createdAt: expect.any(Number),
});

(written by hand, take with a small grain of salt)

http://facebook.github.io/jest/docs/en/expect.html#expectobjectcontainingobject

>All comments

expect(someObj).toEqual(expect.objectContaining({
    name: 'foo',
    surname: 'bar',
    createdAt: expect.any(Number),
}));

or

expect(someObj).toEqual({
    name: 'foo',
    surname: 'bar',
    createdAt: expect.any(Number),
});

(written by hand, take with a small grain of salt)

http://facebook.github.io/jest/docs/en/expect.html#expectobjectcontainingobject

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Antho2407 picture Antho2407  路  3Comments

StephanBijzitter picture StephanBijzitter  路  3Comments

stephenlautier picture stephenlautier  路  3Comments

ticky picture ticky  路  3Comments

Secretmapper picture Secretmapper  路  3Comments