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

Add additional tests for other methods affected by #1369. #1387

Merged
merged 3 commits into from Mar 13, 2019

Conversation

developit
Copy link
Member

@coveralls
Copy link

coveralls commented Mar 10, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 3535087 on tests-scu-state into 8042857 on master.

@mochiya98
Copy link
Contributor

mochiya98 commented Mar 11, 2019

good point! thanks.
but i think that it is not affected by #1369.
maybe we need test of the updated state with componentWillReceiveProps.
example:

it('should update state when called setState in componentWillReceiveProps', () => {
	let componentState;
	let spyShouldComponentUpdate = sinon.spy();
	let spyComponentWillUpdate = sinon.spy();

	class Foo extends Component {
		constructor(props) {
			super(props);
			this.state = {
				dummy: 0
			};
		}
		componentDidMount() {
			// eslint-disable-next-line react/no-did-mount-set-state
			this.setState({ dummy: 1 });
		}
		render() {
			return <Bar dummy={this.state.dummy} />;
		}
	}
	class Bar extends Component {
		constructor(props) {
			super(props);
			this.state = {
				value: 0
			};
		}
		shouldComponentUpdate(nextProps, nextState) {
			spyShouldComponentUpdate(nextState);
			return true;
		}
		componentWillUpdate(nextProps, nextState) {
			spyComponentWillUpdate(nextState);
		}
		componentWillReceiveProps() {
			this.setState({ value: 1 });
		}
		render() {
			componentState = this.state;
			return <div />;
		}
	}

	render(<Foo />, scratch);
	rerender();

	expect(componentState).to.deep.equal({ value: 1 });
	expect(spyShouldComponentUpdate).to.be.calledWith({ value: 1 });
	expect(spyComponentWillUpdate).to.be.calledWith({ value: 1 });
});

@marvinhagemeister marvinhagemeister merged commit a204473 into master Mar 13, 2019
@marvinhagemeister marvinhagemeister deleted the tests-scu-state branch March 13, 2019 07:15
JoviDeCroock added a commit to JoviDeCroock/preact that referenced this pull request Mar 13, 2019
…eact into fix/select_value_ignored

* 'fix/select_value_ignored' of github.com:JoviDeCroock/preact:
  Add additional tests for other methods affected by preactjs#1369. (preactjs#1387)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants