Skip to content

Commit

Permalink
[Tests] [Refactor] move and share shallow/mount tests to individu…
Browse files Browse the repository at this point in the history
…al files for each method:

 - `Symbol.iterator`
 - `at`
 - `childAt`
 - `children`
 - `closest`
 - `contains`
 - `containsAllMatchingElements`
 - `containsAnyMatchingElements`
 - `containsMatchingElement`
 - `debug`
 - `equals`
 - `every`
 - `everyWhere`
 - `exists`
 - `filter`
 - `filterWhere`
 - `find`
 - `findWhere`
 - `first`
 - `flatMap`
 - `forEach`
 - `get`
 - `getElement`
 - `getElements`
 - `getNode`
 - `getNodes`
 - `hasClass`
 - `hostNodes`
 - `html`
 - `instance`
 - `is`
 - `isEmpty`
 - `isEmptyRender`
 - `key`
 - `last`
 - `map`
 - `matchesElement`
 - `name`
 - `not`
 - `parent`
 - `parents`
 - `prop`
 - `props`
 - `reduce`
 - `reduceRight`
 - `render`
 - `renderProp`
 - `root`
 - `setContext`
 - `setProps`
 - `setState`
 - `simulate`
 - `simulateError`
 - `single`
 - `slice`
 - `some`
 - `someWhere`
 - `state`
 - `tap`
 - `text`
 - `wrap`
 - `unmount`
  • Loading branch information
ljharb committed Mar 19, 2019
1 parent 7f79730 commit edc1caf
Show file tree
Hide file tree
Showing 68 changed files with 11,043 additions and 15,128 deletions.
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -85,6 +85,19 @@ npm run build:watch
npm run test:watch
```

### Tests for functionality shared between `shallow` and `mount`

Tests for a method "foo" are stored in `packages/enzyme-test-suite/test/shared/methods/foo`. The file default exports a function that receives an injected object argument, containing the following properties:
- `Wrap`: e.g. `shallow`, `mount`
- `WrapRendered`: this abstracts around the differences between `shallow` and `mount` - e.g., that the root of a shallow wrapper around `Foo` is what `Foo` *renders*, where the root of a mount wrapper around `Foo` is `Foo` itself. Thus, this function produces a wrapper around what `Foo` renders, regardless of the `Wrap` method used.
- `Wrapper`: e.g. `ShallowWrapper`, `ReactWrapper`
- `WrapperName`: e.g. `"ShallowWrapper"`, `"ReactWrapper"`
- `isShallow`: true if `shallow`. note: needing to use this is a code smell, please avoid.
- `isMount`: true if `mount`. note: needing to use this is a code smell, please avoid.
- `makeDOMElement`: in `mount`, makes a real DOM element; in `shallow`, makes a mock object.

These tests are ran via an explicit list in a `describeMethods` call in the ReactWrapper and ShallowWrapper test files. If you add a new test file for a shared method, you'll need to add its name to both calls.

### Style & Linting

This codebase adheres to the [Airbnb Styleguide](https://github.com/airbnb/javascript) and is
Expand Down

0 comments on commit edc1caf

Please sign in to comment.