forked from arkency/reactjs_koans
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path07-LifecycleMethods.js
More file actions
44 lines (35 loc) · 1.61 KB
/
Copy path07-LifecycleMethods.js
File metadata and controls
44 lines (35 loc) · 1.61 KB
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
41
42
43
44
import LifecycleMethodsComponent from '../src/07-LifecycleMethods.js';
import sinon from 'sinon';
describe("07 - Lifecycle methods", () => {
var component;
describe("Task #1 - emit a console log when the component mounts", () => {
it("should emit 'I'm mounted!' in developer's console", () => {
var mock = sinon.mock(console);
mock.expects("log").once().withArgs("I'm mounted!");
var rootNode = document.body.appendChild(document.createElement('div'));
React.render(React.createElement(LifecycleMethodsComponent), rootNode);
mock.verify();
});
});
describe("Task #2 - emit a console log when the component updates", () => {
it("should emit 'Updated!' in developer's console", () => {
var rootNode = document.body.appendChild(document.createElement('div'));
var component = React.render(React.createElement(LifecycleMethodsComponent), rootNode);
var mock = sinon.mock(console);
mock.expects("log").exactly(2).withArgs("Updated!");
component.setState({ name: "Victor" });
component.forceUpdate();
mock.verify();
});
});
describe("Task #3 - emit a console log when the component unmounts", () => {
it("should emit 'Goodbye, cruel world! :(' in developer's console", () => {
var rootNode = document.body.appendChild(document.createElement('div'));
var component = React.render(React.createElement(LifecycleMethodsComponent), rootNode);
var mock = sinon.mock(console);
mock.expects("log").once().withArgs("Goodbye, cruel world! :(");
React.unmountComponentAtNode(rootNode);
mock.verify();
});
});
});