简体   繁体   中英

Jest Snapshot not being properly formatted with pretty format on updateSnapshot, eg. not having Object or Array added to snapshot

My jest snapshots are failing with an error that shows the version passed in, which has been formatted with pretty-format , doesn't match the snapshot which has not been formatted. 在此处输入图像描述

I'm using jest 28.1.1.

When I run jest -updateSnapshot it updates them without the pretty format.

I tried updating the snapshots but they were coming through without the proper format.

After hours of debugging I found the answer. My code base was using version 28.1.1 but globally I had jest version 29.3.1 running. They've since introduced a breaking change in how they format the snapshots. When I would just jest -updateSnapshot it was using version 29 and updating them without using prettier. But then when I ran it from my package.json scripts it would run version 28 and they wouldn't match.

If I added this to my jest.config.js it worked.

 snapshotFormat: { escapeString: true, printBasicPrototype: true }

But in the end I just updated the dependency to version 29.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM