A Jest serializer to simplify your snapshots.
Sometimes you just want to print an object or a string without all the escapes
and Object [null prototype] {
annotations. When you want that, this is a
simple solution for it.
To help us develop this software sustainably under the MIT license, we ask all individuals and businesses that use it to help support its ongoing maintenance and development via sponsorship.
And please give some love to our featured sponsors 🤩:
Surge * |
Netflix * |
Qwick * |
The Guild * |
Chad Furman * |
Fanatics * |
Dovetail * |
Enzuzo * |
Stellate * |
* Sponsors the entire Graphile suite
yarn add jest-serializer-simple
Then add it to your Jest config:
module.exports = {
testEnvironment: "node",
snapshotSerializers: [`jest-serializer-simple`],
//...
};
To tell Jest that you want the object to be printed simply, you must wrap it in
an object with just the __
key: { __: YOUR_VALUE_HERE }
, for example:
expect({ __: data }).toMatchInlineSnapshot(`
{
forums: [
{
name: 'Cats',
},
{
name: 'Dogs',
},
{
name: 'Postgres',
},
],
}
`);