Allow primitives, objects, arrays and functions as arguments to `toMatchInlineSnapshot`
See original GitHub issue🚀 Feature Proposal
Make toMatchInlineSnapshot
able to handle primitive values (strings, booleans, null, undefined, numbers), objects (deep), arrays (deep), functions (check if it is a function).
Motivation
This is heavily influenced by @aaz’s comment in https://github.com/facebook/jest/pull/7792#issuecomment-460094000 and the motivation is to have more powerful inline snapshots by having the actual values in the code instead of strings representations of them.
Example
expect({
a: 1,
b: "2",
c: true,
d: null,
e: undefined,
f: [1, "2", [false]],
g: () => {}
}).toMatchInlineSnapshot({
a: 1,
b: "2",
c: true,
d: null,
e: undefined,
f: [1, "2", [false]],
g: expect.any(Function)
});
Pitch
The example is the pitch, toMatchInlineSnapshot
is a very powerful tool, and it can do a lot better than just printing strings. Get the data you are trying to snapshot in front of you by just running the tests and change it accordingly writing JS instead of JS in a string.
`
Object {
"a": 1,
"b": "2",
"c": true,
"d": null,
"e": undefined,
"f": Array [
1,
"2",
Array [
false,
],
],
"g": [Function],
}
`
vs
{
a: 1,
b: "2",
c: true,
d: null,
e: undefined,
f: [1, "2", [false]],
g: expect.any(Function)
}
Implementation
Probably will have to be done on top of #7792 , it is good that babel is already being used in that PR as it is the most powerful AST editor out there.
I’d be glad to implement this myself and ideally have it ready for Jest 26.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:11 (3 by maintainers)
Top GitHub Comments
If you want to help debug the OOM problem on #7792 so that we can land it feel free 😂 (half serious 😅 )
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.