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

jest extended snapshot matchers don't work with snapshot name #22

Closed
sparten11740 opened this issue Feb 17, 2025 · 0 comments · Fixed by #25
Closed

jest extended snapshot matchers don't work with snapshot name #22

sparten11740 opened this issue Feb 17, 2025 · 0 comments · Fixed by #25

Comments

@sparten11740
Copy link
Contributor

Jest allows passing a snapshot name to snapshot matchers such as toMatchSnapshot and co, e.g.

expect(obj).toMatchSnapshot('inital state')
expect(obj).toMatchSnapshot('state after reload')

The full test name in that case is suffixed with : ${hint}.

exodus-test always assumes the passed argument to be a property matcher and disregards the overloaded signature

test/src/jest.snapshot.js

Lines 113 to 120 in eec3fa5

const snapOnDisk = (expect, orig, matcher) => {
if (matcher) {
expect(orig).toMatchObject(matcher)
// If we passed, make appear that the above call never happened
const state = expect.getState()
state.assertionCalls--
state.numPassingAsserts--
}

So before even attempting to extract the snapshot from the snapshot file, exodus-test throws in this line because it passes a string to toMatchObject

for reference, these are the supported signatures in jest

{
  toMatchSnapshot<U extends { [P in keyof T]: any }>(propertyMatchers: Partial<U>, snapshotName?: string): R;
  toMatchSnapshot(snapshotName?: string): R;
}
@sparten11740 sparten11740 changed the title jest extended snapshot matchers don't work with snapshot hint jest extended snapshot matchers don't work with snapshot name Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant