Skip to content

Commit

Permalink
Merge pull request #7051 from Sage/delete-enzyme
Browse files Browse the repository at this point in the history
Delete enzyme
  • Loading branch information
edleeks87 authored Nov 5, 2024
2 parents cc39891 + c024fab commit 8a9b988
Show file tree
Hide file tree
Showing 82 changed files with 187 additions and 985 deletions.
33 changes: 4 additions & 29 deletions contributing/testing-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
## Contents

- [Component tests](#component-tests)
- [Enzyme utilities](#enzyme-utilities)
- [React Testing Library test ID tests](#react-testing-library-test-id-tests)
- [Using test ID to query elements](#using-test-id-to-query-elements)
- [Use of Snapshot tests](#use-of-snapshot-tests)
- [Continuous Integration (CI)](#continuous-integration-ci)
- [Browser-based component tests](#browser-based-component-tests)
Expand All @@ -18,35 +17,11 @@ This guide details Carbon's testing setup, common conventions, and utilities ava

## Component tests

> **NOTE**: From March 2024, we're transitioning from Enzyme to [React Testing Library (RTL)](https://testing-library.com/docs/react-testing-library/intro/). Please use RTL where possible when testing new functionality.
We use [Jest](https://jestjs.io/) and [React Testing Library](https://testing-library.com/docs/react-testing-library/intro/) (RTL) for our component tests. Tests should describe the **behaviour of the components** rather than describe the implementation to keep the tests clean and reliable. All props, branches, and paths and each of their conditions need to be tested to meet Carbon's 100% coverage policy.

We use the [Jest](https://jestjs.io/) framework and [Enzyme](https://enzymejs.github.io/enzyme/) library for our component tests. Tests should describe the **behaviour of the components** rather than describe the implementation to keep the tests clean and reliable. All props, branches, and paths and each of their conditions need to be tested to meet Carbon's 100% coverage policy.
### Using test ID to query elements

### Enzyme utilities

To help with common testing scenarios, we have several custom utilities available in `/src/__spec_helper__` that can be imported directly into your tests.

For example, the `assertStyleMatch` method asserts if all the expected CSS properties have been applied to a DOM element or React component:

```tsx
describe("FlatTableRow", () => {
it("then the element should have proper outline when focused", () => {
assertStyleMatch(
{
outline: `3px solid var(--colorsSemanticFocus500)`,
},
wrapper,
{
modifier: ":focus",
}
);
});
});
```

### React Testing Library test ID tests

[RTL](https://testing-library.com/docs/react-testing-library/intro/) follows a user-centric testing approach. To encourage this the library provides query functions for locating DOM elements by user-facing attributes like text, ARIA roles, etc.
RTL follows a user-centric testing approach. To encourage this the library provides query functions for locating DOM elements by user-facing attributes like text, ARIA roles, etc.

If you need to use [RTL's `*ByTestId()` query functions](https://testing-library.com/docs/queries/bytestid), we have configured RTL to locate the `data-role` attribute:

Expand Down
4 changes: 0 additions & 4 deletions enzyme.config.js

This file was deleted.

4 changes: 1 addition & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ const isCI = process.env.CI === "true";

const config: Config = {
notify: false,
setupFiles: ["raf/polyfill", "<rootDir>/enzyme.config.js"],
setupFiles: ["raf/polyfill"],
testEnvironment: "jsdom",
setupFilesAfterEnv: [
"<rootDir>/src/__spec_helper__/__internal__/index.ts",
"<rootDir>/src/__spec_helper__/__internal__/expect.ts",
"jest-canvas-mock",
],
snapshotSerializers: ["enzyme-to-json/serializer"],
testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"],
testPathIgnorePatterns: ["node_modules", "lib", "esm"],
moduleDirectories: ["src", "node_modules"],
Expand Down
Loading

0 comments on commit 8a9b988

Please sign in to comment.