Skip to content

bobderrico80/writing-clean-js-tests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Writing Clean JavaScript Tests

A set of code examples for my talk: Writing Clean JavaScript Tests: Avoiding 10 Common Mistakes That Make Our Test Code Messy.

The common mistakes (and their solutions) illustrated here are:

  1. Duplicating test setup code
  2. Not properly grouping tests
  3. Repeating complicated setup steps
  4. Hiding test data
  5. Not using dynamic tests
  6. Leaking state between tests
  7. Writing confusing (or broken) async tests
  8. Unclear test descriptions
  9. Neglecting tests
  10. Not writing tests

Slides for the talk can be found here

Project organization

The src/ folder contains all of the modules/functions/classes that will be used in the tests.

The test-messy/ folder contains versions of the tests containing the common mistakes. These are numbered 01 through 10 corresponding with the list above.

The test-clean/ folder contains versions of the tests with the mistakes fixed. These are named with the same corresponding numbers.

Project scripts

npm test will run the tests with the Jest test runner

npm run lint will run the ESLint task.

This project will also run both tasks on pre-commit, and prevent committing if one or both fail. NOTE: Since one of the 'messy' tests contains intentional ESLint errors, --no-verify must be used when committing (unless the errors get fixed!).

About

Code samples for my talk 'Writing Clean JavaScript Tests'

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published