Skip to content

Commit

Permalink
Implement Jest's test framework setup configuration file
Browse files Browse the repository at this point in the history
The setup documentation (1) provides instruction for best practices on
how to configure the library for a optimal and easy developer workflow.
This includes a global configuration that has been placed within the
`test` base directory named `setup.js` and will be loaded via Jest's
`setupTestFrameworkScriptFile` option .
Initially it imports the `react-testing-library/cleanup-after-each`
script which will automatically execute `afterEach(cleanup)` for each
test which prevents unnecessary boilerplate per test file and possible
problems when the function is not called accidentally. It also imports
`jest-dom/extend-expect` to automatically extend the `expect` global
with jest-dom's custom matchers (2).

References:
  (1) https://github.com/kentcdodds/react-testing-library#setup
  (2) https://github.com/gnapse/jest-dom#custom-matchers

GH-39
  • Loading branch information
arcticicestudio committed Nov 24, 2018
1 parent f944501 commit 3693df0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2018-present Arctic Ice Studio <[email protected]>
* Copyright (C) 2018-present Sven Greb <[email protected]>
*
* Project: Nord Docs
* Repository: https://github.com/arcticicestudio/nord-docs
* License: MIT
*/

/**
* @file The setup to configure Jest's test framework before each test.
* @author Arctic Ice Studio <[email protected]>
* @author Sven Greb <[email protected]>
* @see https://jestjs.io/docs/en/configuration
* @see https://www.gatsbyjs.org/docs/testing
* @since 0.1.0
*/

/*
* Extend the `expect` global with jest-dom's custom matchers.
*
* @see https://github.com/gnapse/jest-dom#custom-matchers
*/
import "jest-dom/extend-expect";

/*
* Automatically execute `afterEach(cleanup)` for each test.
*/
import "react-testing-library/cleanup-after-each";

0 comments on commit 3693df0

Please sign in to comment.