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

Feature Request: reuse the same snapshot in multiple places #38

Closed
andykais opened this issue Apr 5, 2019 · 1 comment
Closed

Feature Request: reuse the same snapshot in multiple places #38

andykais opened this issue Apr 5, 2019 · 1 comment

Comments

@andykais
Copy link

andykais commented Apr 5, 2019

I have a use case like so:

it('should make sure the return value doesnt change', async () => {
  const resultPre = getResult()
  expect(resultPre).to.matchSnapshot()
  await runSomeSideEffect()
  const resultPost = getResult()
  expect(resultPost).to.matchSnapshot()
})
exports['should make sure the return value doesnt change 1'] = ...
exports['should make sure the return value doesnt change 2'] = ...

This works fine by ensuring that the snapshots do not change, but it duplicates what is the same output and gives a slightly misleading error if it fails.

It would be great if there was a way to specify reusing the same snapshot in different places. For example:

import { createSnapshotKey } from 'chai-jest-snapshot'
const snapshotKey = createShapshotKey()

it('should make sure the return value doesnt change', () => {
  ...
  expect(resultPre).to.matchSnapshot(snapshotKey)
  ...
  expect(resultPost).to.matchSnapshot(snapshotKey)
  // both reference exports['should make sure the return value doesnt change 1']=...
})
@andykais
Copy link
Author

andykais commented Apr 5, 2019

arg wait! I found an obvious solution

it('should make sure the return value doesnt change', async () => {
  const resultPre = getResult()
  expect(resultPre).to.matchSnapshot()
  await runSomeSideEffect()
  const resultPost = getResult()
  expect(resultPost).to.deep.equal(resultPre)
})

Im closing this now, but feel free to open it again if there is anything else to discuss

@andykais andykais closed this as completed Apr 5, 2019
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

No branches or pull requests

1 participant