Jest: Omit non-enumerable, symbolic members in snapshots

Created on 30 Nov 2018  路  6Comments  路  Source: facebook/jest

馃悰 Bug Report

When upgrading from MobX 4.3.0 to 5.6.0, new snapshot information is created using jest

This information is largely extraneous, and when added typically triples the size of the snapshot file (best case) and sometimes grows file by 10x (worst case)

exports[`Size Picker Snapshot not clicked 1`] = `
<MuiThemeProvider>
  <SizePicker
    store={
      SizePickerStore {
        "defaultValue": 8,
        "idPrefix": "size-picker",
        "internalId": "1",
        "isExpanded": false,
        "isMousePressed": false,
        "label": undefined,
        "onChange": Event {
          "listeners": Array [],
          "publishRecursionCount": 0,
        },
        "onHideShow": [Function],
        "onKeyDown": [Function],
        "onMouseDown": [Function],
        "onMouseUp": [Function],
        "value": 8,
+      Symbol(mobx did run lazy initializers): true,
+      Symbol(mobx administration): ObservableObjectAdministration$$1 {
+      "defaultEnhancer": [Function],
+      "keysAtom": Atom$$1 {
+        "diffValue": 0,
+        "isBeingObserved": false,
+        "isPendingUnobservation": false,
+        "lastAccessedBy": 0,
+        "lowestObserverState": 2,
+        "name": "[email protected]",
+        "observers": Set {},
          },
          "name": "SizePickerStore@26",
          "target": [Circular],
          "values": Map {
            "value" => 8,
            "isExpanded" => false,
            "label" => undefined,
          },
        },
      }
    }
  >

To Reproduce

Steps to reproduce the behavior: Using mobx and mobx-react, create an @observer react component that receives props including an @observable object. Write a test file that mounts this component and takes a snapshot

Expected behavior

according to @mweststrate of MobX:
the problem is that it should ignore non-enumerable (symbolic) members. It was fixed a while ago for toEqual, but not yet for snapshots

link to mobx issue

Run npx envinfo --preset jest

System:
    OS: Windows 10
    CPU: (8) x64 Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz
  Binaries:
    Node: 10.13.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.12.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 5.0.4 - C:\Program Files\nodejs\npm.CMD

Most helpful comment

Suggested alternative title for this issue: _Omit non-enumerable, symbolic members in snapshots_

All 6 comments

For some background, at first glance it seems that snapshots are accidentally taking non-enumerable, symbolic members into account. This was originally the case for toEquals as well, but has been addressed in https://github.com/facebook/jest/pull/6398. I think it would make sense that snapshots follows the same semantics.

I am willing to attempt a PR to achieve the mentioned behavior

It might help the large jsdom snapshots as well...

/cc @pedrottimark @rickhanlonii @thymikee thoughts?

Suggested alternative title for this issue: _Omit non-enumerable, symbolic members in snapshots_

Since we've changed this behavior for toEqual, I think it makes sense to adjust snapshots this way as well.
EDIT: Another breaking change as well 馃槄

@austinalameda thanks for reporting and thanks for dropping in with the info @mweststrate

If we're going to do it, let's do it now before the next major

Another option (either in the short term or long term) may be to add a custom serializer

Yes to making pretty-format consistent with toEqual matcher. It will help with jsdom too.

I will make pull request.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paularmstrong picture paularmstrong  路  3Comments

ticky picture ticky  路  3Comments

StephanBijzitter picture StephanBijzitter  路  3Comments

gustavjf picture gustavjf  路  3Comments

jardakotesovec picture jardakotesovec  路  3Comments