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

Snapshots not storing function names in Saga objects #2580

Closed
outdooricon opened this issue Jan 12, 2017 · 4 comments
Closed

Snapshots not storing function names in Saga objects #2580

outdooricon opened this issue Jan 12, 2017 · 4 comments

Comments

@outdooricon
Copy link

When I run a test against a Redux Saga Call event, If I want to store the result in a snapshot, the function name being called is important. However, currently when I store it as a snapshot, the function name isn't serialized into the snapshot.

For a test:

describe('Saga', () => {
  const generator = sagaGenerator();
  it('should call fetch command', () => {
    const firstCmd = generator.next().value;
    expect(firstCmd).toEqual(call(fetchCall));
  });
});

Here is what gets put into the snapshot:

exports[`Saga should call fetch command 1`] = `
Object {
  "@@redux-saga/IO": true,
  "CALL": Object {
    "args": Array [],
    "context": null,
    "fn": [Function],
  },
}
`;

However, this is what the test says in the console that it is comparing against when I don't use a snapshot:

Object {
  "@@redux-saga/IO": true,
  "CALL": Object {
    "args": Array [],
    "context": null,
    "fn": [Function fetchCall],
  },
}

Note the Function fetchCall. Without that function name, the snapshot will pass easily for any functions

@thymikee
Copy link
Collaborator

I thought it was a bug, but we actually have this behaviour on purpose: https://github.com/facebook/jest/blob/master/packages/jest-snapshot/src/utils.js#L65

@cpojer why would we do that?

@cpojer
Copy link
Member

cpojer commented Jan 13, 2017

The problem is that function names are not reliable and they also aren't visible in the real user output. It's like testing a private function of a module – if it is important, you should expose it somehow.

Concrete examples where this creates issues:

  • node 4 and node 6 have different function name inference
  • coverage messes with the function names, so snapshots break when using coverage

See http://facebook.github.io/jest/blog/2016/10/03/jest-16.html#snapshot-updates

@cpojer cpojer closed this as completed Jan 13, 2017
@cpojer cpojer removed the Confirmed label Jan 13, 2017
@outdooricon
Copy link
Author

Thank you Christoph! Is there another way to test Saga call actions then, using snapshot, or do you just recommend not using it for those?

@github-actions
Copy link

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 May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants