Skip to content

Instantly share code, notes, and snippets.

@gravitinos
Created October 4, 2018 17:57
Show Gist options
  • Select an option

  • Save gravitinos/8b8b2d621d82557769de846693b74e71 to your computer and use it in GitHub Desktop.

Select an option

Save gravitinos/8b8b2d621d82557769de846693b74e71 to your computer and use it in GitHub Desktop.
Specifically around Jest

Testing Trophy

#testing

Unit

  • Unit test small modules of code.
  • Mock all dependencies with exceptions (React, Alm.queryBuilder)
  • Small snapshot tests
  • Make sure stubs are called if you want side effects of components
  • Avoid testing react internals

Integration

  • Tests how the pieces fit together
  • Mocks API requests
  • tests multiple units of code

Jest

#work #testing

Snapshot testing

Effective Snapshot Testing – kentcdodds Important points wherer snapshots fail

  • Intention
  • generated (devs don't pay attention)
  • false negatives?
  • Fails even if it still "works"

Avoid

  • huge snapshots

Utilities

  • eslint-plugin-jest called “no-large-snapshots”
  • snapshot-diff

Reflection on Snapshot

Snapshot testing still feels pretty useful to me, but it’s apparent that we can abuse this tool. This tool does not enforce much, which makes it dangerous. The no large snapshots seems to be something we should introduce ASAP. We should also use snapshot diff while we can, and make sure our components are small. This makes me question if we should unit test things like Page.js’s. It feels like they should be integration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment