-
Notifications
You must be signed in to change notification settings - Fork 8
/
task-12_state.js
40 lines (29 loc) · 954 Bytes
/
task-12_state.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React from '../react';
import '../test-utils';
class Greeting extends React.Component {
constructor(props) {
super(props);
this.state = { name: 'world', moreState: 'right here' };
}
render() {
const { name } = this.state;
return <p>Hello {name}</p>;
}
}
test('Check Component correctly updates state', () => {
const element = new Greeting();
element.setState({ name: 'universe' });
expect(element.state.name).toBe('universe');
});
test('Check Component only changes given state', () => {
const element = new Greeting();
element.setState({ name: 'universe' });
expect(element.state.name).toBe('universe');
expect(element.state.moreState).toBe('right here');
});
test('Check Component does not change state if new state is null', () => {
const element = new Greeting();
element.setState(null);
expect(element.state.name).toBe('world');
expect(element.state.moreState).toBe('right here');
});