Skip to content

Commit

Permalink
Merge 6f60a00 into 6ad2165
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 1, 2019
2 parents 6ad2165 + 6f60a00 commit e87ffd5
Show file tree
Hide file tree
Showing 73 changed files with 11,238 additions and 15,166 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -15,7 +15,7 @@ before_script:
script:
- 'if [ -n "${LINT-}" ]; then npm run lint; elif [ -n "${KARMA-}" ]; then npm run test:karma -- --single-run; elif [ -n "${REACT-}" ]; then npm run travis; else false ; fi'
after_script:
- 'if [ -n "${REACT-}" ]; then case "${TRAVIS_NODE_VERSION}" in "10" | "4" | "0.12") cat ./coverage/lcov.info | ./node_modules/.bin/coveralls ;; esac ; fi'
- 'if [ -n "${REACT-}" ]; then case "${TRAVIS_NODE_VERSION}" in "8" | "6") ;; *) cat ./coverage/lcov.info | ./node_modules/.bin/coveralls ;; esac ; fi'
sudo: false
matrix:
fast_finish: true
Expand Down
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
37 changes: 36 additions & 1 deletion packages/enzyme-test-suite/test/Adapter-spec.jsx
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { expect } from 'chai';
import jsdom from 'jsdom';
import { get } from 'enzyme/build/configuration';
import { configure, shallow } from 'enzyme';
import { configure, shallow, EnzymeAdapter } from 'enzyme';
import inspect from 'object-inspect';
import {
Portal,
Expand Down Expand Up @@ -77,6 +77,41 @@ describe('Adapter', () => {
});
});

describe('base class', () => {
it('constructs', () => {
const instance = new EnzymeAdapter();
expect(instance).to.have.property('options');
expect(instance.options).to.be.an('object');
});

it('throws on abstract methods', () => {
expect(() => new EnzymeAdapter().createRenderer()).to.throw(
Error,
'createRenderer is a required method of EnzymeAdapter, but was not implemented.',
);
expect(() => new EnzymeAdapter().nodeToElement()).to.throw(
Error,
'nodeToElement is a required method of EnzymeAdapter, but was not implemented.',
);
expect(() => new EnzymeAdapter().isValidElement()).to.throw(
Error,
'isValidElement is a required method of EnzymeAdapter, but was not implemented.',
);
expect(() => new EnzymeAdapter().createElement()).to.throw(
Error,
'createElement is a required method of EnzymeAdapter, but was not implemented.',
);
});

describe('invokeSetStateCallback', () => {
it('has the right length', () => {
expect(EnzymeAdapter.prototype).to.have.property('invokeSetStateCallback');
expect(EnzymeAdapter.prototype.invokeSetStateCallback).to.be.a('function');
expect(EnzymeAdapter.prototype.invokeSetStateCallback).to.have.lengthOf(2);
});
});
});

describeWithDOM('mounted render', () => {
function hydratedTreeMatchesUnhydrated(element, hydrate = false) {
const markup = renderToString(element);
Expand Down

0 comments on commit e87ffd5

Please sign in to comment.