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

Snapshot mock #4829

Closed
mjesun opened this issue Nov 2, 2017 · 10 comments
Closed

Snapshot mock #4829

mjesun opened this issue Nov 2, 2017 · 10 comments

Comments

@mjesun
Copy link
Contributor

mjesun commented Nov 2, 2017

I just updated to [email protected] and found what appears to be wrong snapshotting for mocked functions:

    @@ -54,13 +54,22 @@
          />
        }
        refreshing={false}
        relay={
          Object {
    -       "hasMore": [Function],
    -       "loadMore": [Function],
    -       "refetchConnection": [Function],
    +       "hasMore": Object {
    +         "calls": Array [],
    +         "name": "jest.fn()",
    +       },
    +       "loadMore": Object {
    +         "calls": Array [],
    +         "name": "jest.fn()",
    +       },
    +       "refetchConnection": Object {
    +         "calls": Array [],
    +         "name": "jest.fn()",
    +       },
          }
        }

Is this expected (i.e. should I run with -u?)

@mjesun mjesun added the Question label Nov 2, 2017
@cpojer
Copy link
Member

cpojer commented Nov 2, 2017

I think this was an intentional change. cc @pedrottimark

@SimenB
Copy link
Member

SimenB commented Nov 2, 2017

This is #4668. Did not think of this case... IMO it's fine :D

@pedrottimark
Copy link
Contributor

@SimenB You were thinking snapshot of mock function itself to see how it was called?

Thinking of possible objections in this context, the snapshot changes:

  • if you change from ordinary function to mock function, or the opposite
  • if you change when you take snapshot compared to when the mock function is called

@SimenB
Copy link
Member

SimenB commented Nov 2, 2017

if you change from ordinary function to mock function, or the opposite

This is fine. If you really want a stub, pass () => {}.

if you change when you take snapshot compared to when the mock function is called

Not as clear, but if I'm moving where the snapshot is taken, I'd not be too surprised at having to update the snapshots (and the invocations of that function does change, so, if anything, it's more accurate than just function). That said, I'm not sure what's the most ergonomic for users here

@cpojer
Copy link
Member

cpojer commented Nov 2, 2017

Yeah, I think it is fine to keep it.

@cpojer cpojer closed this as completed Nov 2, 2017
@mjesun
Copy link
Contributor Author

mjesun commented Nov 2, 2017

OK; I have two things then:

  • This is probably a breaking change, so should release be jest@22?
  • Is it OK that an object with the same structure will match?

@SimenB
Copy link
Member

SimenB commented Nov 3, 2017

This is probably a breaking change, so should release be jest@22?

Current master has a few breaking changes (this should also be marked as one), so I think the next release will be 22 anyways.

Is it OK that an object with the same structure will match?

I'm inclined to say yes, but maybe we could somehow change the header from Object to (Jest)Spy?

@cpojer
Copy link
Member

cpojer commented Nov 3, 2017

@SimenB yeah, I think it makes sense to change it from Object to "MockFunction { … }"?

@mjesun
Copy link
Contributor Author

mjesun commented Nov 3, 2017

Love it. +1 to MockFunction. I created #4835 for that.

@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
@SimenB SimenB removed the Question label Feb 25, 2022
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

4 participants