Skip to content

Commit

Permalink
adjust documentation to reflect reality
Browse files Browse the repository at this point in the history
add missing setContext test
  • Loading branch information
jwbay committed Mar 15, 2017
1 parent 9fc50dc commit 5dda4f8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/api/shallow.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ describe('<MyComponent />', () => {
2. `options` (`Object` [optional]):
- `options.context`: (`Object` [optional]): Context to be passed into the component
- `options.disableLifecycleMethods`: (`Boolean` [optional]): If set to true, `componentDidMount`
and `componentDidUpdate` are not called on the component. Allows `shallow` to be
used when testing components that assume refs or DOM nodes are available during these methods
is not called on the component, and `componentDidUpdate` is not called after
[`setProps`](ShallowWrapper/setProps.md) and [`setContext`](ShallowWrapper/setContext.md).

#### Returns

Expand Down
4 changes: 2 additions & 2 deletions src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function validateOptions(options) {
const { lifecycleExperimental, disableLifecycleMethods } = options;
if (
typeof lifecycleExperimental !== 'undefined' &&
lifecycleExperimental !== !!lifecycleExperimental
typeof lifecycleExperimental !== 'boolean'
) {
throw new Error(
'lifecycleExperimental must be either true or false if provided',
Expand All @@ -80,7 +80,7 @@ function validateOptions(options) {

if (
typeof disableLifecycleMethods !== 'undefined' &&
disableLifecycleMethods !== !!disableLifecycleMethods
typeof disableLifecycleMethods !== 'boolean'
) {
throw new Error(
'disableLifecycleMethods must be either true or false if provided',
Expand Down
20 changes: 18 additions & 2 deletions test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2747,13 +2747,20 @@ describe('shallow', () => {
}
}

const options = {
disableLifecycleMethods: true,
context: {
foo: 'foo',
},
};

beforeEach(() => {
wrapper = shallow(<Foo />, { disableLifecycleMethods: true });
wrapper = shallow(<Foo />, options);
spy.reset();
});

it('does not call componentDidMount when mounting', () => {
wrapper = shallow(<Foo />, { disableLifecycleMethods: true });
wrapper = shallow(<Foo />, options);
expect(spy.args).to.deep.equal([
['componentWillMount'],
['render'],
Expand All @@ -2770,6 +2777,15 @@ describe('shallow', () => {
]);
});

it('calls expected methods when receiving new context', () => {
wrapper.setContext({ foo: 'foo' });
expect(spy.args).to.deep.equal([
['shouldComponentUpdate'],
['componentWillUpdate'],
['render'],
]);
});

it('calls expected methods for setState', () => {
wrapper.setState({ bar: 'bar' });
expect(spy.args).to.deep.equal([
Expand Down

0 comments on commit 5dda4f8

Please sign in to comment.