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

[Bug]: non-enumerable symbols are not excluded when calling toMatchObject #14669

Closed
fa93hws opened this issue Nov 2, 2023 · 2 comments
Closed

Comments

@fa93hws
Copy link
Contributor

fa93hws commented Nov 2, 2023

Version

29.7.0

Steps to reproduce

  1. Clone https://github.com/fa93hws/jest-mobx-ts-jest-matchobject-issue
  2. npm install
  3. npm run test
  4. error occours

Expected behavior

They should match

Actual behavior

They didn't match

   - Expected  -  1
    + Received  + 33

    - Store {
    + Object {
        "foo": false,
    +   Symbol(mobx administration): Object {
    +     "appliedAnnotations_": Object {
    +       "foo": [Function decorator],
    +     },
    +     "changeListeners_": undefined,
    +     "defaultAnnotation_": Object {
    +       "annotationType_": "true",
    +       "extend_": [Function extend_$5],
    +       "make_": [Function make_$5],
    +       "options_": undefined,
    +     },
    +     "interceptors_": undefined,
    +     "isPlainObject_": false,
    +     "keysAtom_": Object {
    +       "diffValue_": 0,
    +       "isBeingObserved_": false,
    +       "isPendingUnobservation_": false,
    +       "lastAccessedBy_": 0,
    +       "lowestObserverState_": 2,
    +       "name_": "[email protected]",
    +       "observers_": Set {},
    +       "onBOL": undefined,
    +       "onBUOL": undefined,
    +     },
    +     "name_": "Store@1",
    +     "pendingKeys_": undefined,
    +     "proxy_": undefined,
    +     "target_": [Circular],
    +     "values_": Map {
    +       "foo" => false,
    +     },
    +   },

Additional context

The issues has occurred before mobxjs/mobx#1613 and is fixed in https://github.com/jestjs/jest/pull/7448/files.

It works fine on [email protected] but breaks after I upgrade it to [email protected]

For curiosity, I add some console.log to my test and I see these symbols are not enumerable.

describe('store', () > {
  it('should match', () => {
    const store = new Store();
    store.foo = false;
    const anotherStore = new Store();

    Object.getOwnPropertySymbols(store).forEach(s => {
      const isEnumerable = Object.getOwnPropertyDescriptor(store, s).enumerable;
      console.log(s, 'store', isEnumerable);
    });

    Object.getOwnPropertySymbols(anotherStore).forEach(s => {
      const isEnumerable = Object.getOwnPropertyDescriptor(anotherStore, s).enumerable;
      console.log(s, 'anotherStore', isEnumerable);
    });

    expect(store).toMatchObject(anotherStore);
  })
})

However, when adding console.log to code in pretty-format in getKeysOfEnumerableProperties function, these symbols become enumerable.

Environment

System:
    OS: macOS 13.6.1
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 20.8.1 - /opt/homebrew/bin/node
    Yarn: 1.22.18 - /opt/homebrew/bin/yarn
    npm: 10.1.0 - /opt/homebrew/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
@fa93hws
Copy link
Contributor Author

fa93hws commented Nov 2, 2023

I think it's coming from https://github.com/jestjs/jest/pull/13810/files#diff-ea0772cb42734a243358c7e99a69721433082bcb6ea3ef28fa79129bc0d59431R54

const getObjectKeys = object => [
  ...Object.keys(object),
  ...Object.getOwnPropertySymbols(object).filter(s => Object.getOwnPropertyDescriptor(object, s).enumerable)
];

solves the issue, but I'm not sure whether that's expected?
Anyway I will jest send a PR

Copy link

github-actions bot commented Dec 3, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant