Skip to content

Commit

Permalink
Test/orr/migrate karma to jest (#379)
Browse files Browse the repository at this point in the history
* feat: move to jest

* Butotn tests

* Link Tests

* Link Tests

* test: FormattedNumber

* test: Loader

* test: small changes

* ifnra: update test

* remove: karma sinon and mocha

* remove: karma sinon and mocha

* test: update coverage

* fix: testing

* fix: testing

* fix: lint

* fix: lint and stylelint

* fix: storyshoots tests

* uupdate node-sass

* remove errors
  • Loading branch information
orrgottlieb authored Dec 7, 2021
1 parent 42e8ab9 commit 55a2177
Show file tree
Hide file tree
Showing 53 changed files with 3,022 additions and 2,732 deletions.
9 changes: 0 additions & 9 deletions TESTING_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,13 @@ We are using two approaches when regarding testing the first is the standard jes
1. Jest as of our test runner and framework
2. [React testing library](https://testing-library.com/docs/react-testing-library/intro) as our components testing library

The second approach is for special use cases which require a browser (positing, observer callbacks ...)
1. Karma as our test runner
2. Mocha as our framework library
3. Sinon as our mocks/stubs library
4. [React testing library](https://testing-library.com/docs/react-testing-library/intro) as our components testing library

## React testing library
This library forces us to test according to user behaviour and not implementation details (state keys for example) for example the library allows you to target elements according to text, aria labels, placeholders text and more. This approach ensure us that we test the component in the right way and allows us easier refactoring when needed.

#### Test File
#### Jest
Use our plop which automatically generates the proper folder structure, each file should end with .test.js

#### Karma
The file should end with `-test.js` and should be located in a `__tests__` folder.

### React testing 101
#### Mounting components
In react testing library we "mount" the entire components and the tests are running against a fully rendered tree in order to simulate the most accurate user environment.
Expand Down
File renamed without changes.
17 changes: 6 additions & 11 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],
coveragePathIgnorePatterns: ["node_modules/", "src/components/Icon/Icons/"],

// Indicates which provider should be used to instrument code for coverage
// coverageProvider: "babel",
Expand Down Expand Up @@ -73,15 +74,7 @@ module.exports = {
// ],

// An array of file extensions your modules use
moduleFileExtensions: [
"js",
"json",
"jsx",
"ts",
"tsx",
"node",
"mdx"
],
moduleFileExtensions: ["js", "json", "jsx", "ts", "tsx", "node", "mdx"],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
Expand Down Expand Up @@ -176,14 +169,16 @@ module.exports = {
// A map from regular expressions to paths to transformers
transform: {
"^.+\\.[tj]sx?$": "babel-jest",
"^.+\\.mdx?$": "@storybook/addon-docs/jest-transform-mdx"
"^.+\\.mdx?$": "@storybook/addon-docs/jest-transform-mdx",
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/__mocks__/fileMock.js"
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
transformIgnorePatterns: [
"node_modules/(?!monday-ui-style)/"
// "\\.pnp\\.[^\\/]+$"
],
]

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
Expand Down
120 changes: 0 additions & 120 deletions karma.conf.js

This file was deleted.

Loading

0 comments on commit 55a2177

Please sign in to comment.