Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include symbol keys when diffing objects #13810

Merged
merged 2 commits into from
Jan 25, 2023

Commits on Jan 24, 2023

  1. Include symbol keys when diffing objects

    As a result of jestjs#13639, `expect.toMatchObject` can now compare symbol keys.  However, the diffs that it generates if a symbol key doesn't match are misleading.  For example, the following assertion:
    
    ```
    const Foo = Symbol("foo");
    test("mismatched symbols", () => {
      expect({ a: 1, [Foo]: {id: 1} }).toMatchObject({ a: 1, [Foo]: {id: 2} });
    });
    ```
    
    fails as desired, but it displays the following diff:
    
    ```
        - Expected  - 3
        + Received  + 0
    
          Object {
            "a": 1,
        -   Symbol(foo): Object {
        -     "id": 2,
        -   },
          }
    ```
    
    *Note*: In inspecting the code, I wonder if `getObjectSubset` should use the same logic as `subsetEquality` - i.e., if `subsetEquality` does not evaluate an object's inherited string keys when determining equality, then `getObjectSubset` should not evaluate an object's inherited string keys for reporting on inequality? To put it another way - jestjs#13639 appears to change `subsetEquality` from considering an object's inherited string keys to not considering inherited string keys, and I'm not sure if that was intentional in a SemVer-minor change.  For now, I've preserved the previous behavior, but let me know if this should change.
    
    Fixes jestjs#13809
    joshkel committed Jan 24, 2023
    Configuration menu
    Copy the full SHA
    740a8d3 View commit details
    Browse the repository at this point in the history
  2. Update changelog

    joshkel committed Jan 24, 2023
    Configuration menu
    Copy the full SHA
    f5942b4 View commit details
    Browse the repository at this point in the history