Snapshotting <select>.options breaks in pretty-format
See original GitHub issue🐛 Bug Report
Snapshotting the options
property on a <select>
element breaks in pretty-format
.
Jest v22.1.2 on node v7.4.0 (the provided repl.it, see below) fails with:
TypeError: Cannot delete property 'cldr' of #<Object>
at printObjectProperties (../../usr/local/share/.config/yarn/global/node_modules/pretty-format/build/collections.js:140:32)
Jest v23.6.0 on Node 10.11.0 (locally) fails with:
TypeError: Method get TypedArray.prototype.length called on incompatible receiver [object Object]
at Uint8Array.get length [as length] (<anonymous>)
at printComplexValue (../../node_modules/pretty-format/build/index.js:200:24)
To Reproduce
Create a <select>
with at least one <option>
, then attempt to snapshot select.options
:
it('snapshots select options', () => {
const select = document.createElement('select');
select.innerHTML = '<option value="one">one</option>';
expect(select.options).toMatchSnapshot();
});
Expected behavior
A snapshot should be created with the content of the options collection.
Link to repl or repo (highly encouraged)
https://repl.it/repls/CurvyKnobbyModel
Run npx envinfo --preset jest
Paste the results here:
System:
OS: macOS High Sierra 10.13.6
CPU: x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Binaries:
Node: 10.11.0 - /usr/local/bin/node
Yarn: 1.10.1 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
npmPackages:
jest: ^23.6.0 => 23.6.0
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Jest Snapshot not being properly formatted with pretty format ...
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...
Read more >How To Write Snapshot Tests For React Components With Jest
In this tutorial, we will be looking at what snapshot tests are and how we ... likelihood that those changes may cause something...
Read more >pretty-formats Documentation - Git
If the commit is a merge, and if the pretty-format is not oneline, email or raw, an additional line is inserted before the...
Read more >User's Manual - CAMotics
It is possible to save a 3D model of the cut surface, the tool path, or a snapshot of the Simulation View or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@SimenB Thanks for cc. Notice HTML elements from
jsdom
instead of React elements 😃Problem:
pretty-format
fails to serialize internals of a simulated DOM object instance as a generic object, because built-in snapshot serializers don’t match the class ofselect.options
property:Solution: Explicitly convert
options
orchildren
property from array-like object to JavaScript array:Here is the stored snapshot:
Although the thought has crossed my mind whether built-in plugins could support
HTMLCollection
orNodeList
object instances created in browser or byjsdom
package, so far I decided not, because everyone pays in every snapshot test for each additional test condition.@theneva If this change to the assertion works for you, can you please close the issue?
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.