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 testing #346

Closed
dsseng opened this issue Apr 17, 2019 · 4 comments
Closed

Snapshot testing #346

dsseng opened this issue Apr 17, 2019 · 4 comments

Comments

@dsseng
Copy link
Contributor

dsseng commented Apr 17, 2019

Add .toMatchSnapshot() matcher to testing module

@j-f1
Copy link

j-f1 commented Apr 17, 2019

What should the format be? Jest uses a CommonJS-inspired format, so here’s a few suggestions:

// test code
test(function doThingA() {
  assertMatchesSnaphot(foo)
})
test({
  name: 'do thing B',
  fn() {
    assertMatchesSnaphot(foo)
  }
})

// option 1
import 'https://deno.land/std/testing/snapshot/v1.ts'
export default {
  doThingA: [`blah blah`],
  'do thing B': [`blah blah`]
}

// option 2
import 'https://deno.land/std/testing/snapshot/v1.ts' 

export const doThingA = [`blah blah`]
export const do__thing__B = [`blah blah`]

@dsseng
Copy link
Contributor Author

dsseng commented Apr 17, 2019

@j-f1 look at jest

@j-f1
Copy link

j-f1 commented Apr 18, 2019

Jest uses this format:

// Jest Snapshot v1, https://goo.gl/fbAQLP

[ if the snapshot is single-line ]
exports[`test name here 1`] = `foo`

[ if the snapshot is multiline ]
exports[`test name here 2`] = `
foo
bar
`

My two snapshot proposals alter this in a few ways:

  1. Instead of using an implict comment, an explicit import is used.
  2. Instead of creating multiple snapshots for each test with repetitions of the test name, I use an array.
  3. ESM is used instead of CommonJS

@j-f1
Copy link

j-f1 commented Apr 18, 2019

Here’s another proposal: eschew the JS format altogether

Deno snapshot v1, https://deno.land/std/testing/snapshot/v1.md

snapshot `test name here` [`
  foo
`, `
  foo
  bar
`]

snapshot `another test` [`foo`, `foo bar`]

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

3 participants