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

Test/orr/migrate karma to jest #379

Merged
merged 20 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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