forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugLine.js
More file actions
95 lines (85 loc) · 2.71 KB
/
DebugLine.js
File metadata and controls
95 lines (85 loc) · 2.71 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import React from "react";
import { shallow } from "enzyme";
import DebugLine from "../DebugLine";
jest.mock("../../../utils/editor/source-documents", () => ({
getDocument: jest.fn()
}));
import { getDocument } from "../../../utils/editor/source-documents";
const mockGetDocument = {
addLineClass: jest.fn(),
removeLineClass: jest.fn()
};
getDocument.mockImplementation(() => mockGetDocument);
function generateDefaults(overrides) {
return {
editor: {
codeMirror: {
markText: () => ({ clear: jest.fn() })
}
},
selectedFrame: {
location: {
sourceId: "x",
line: 2
}
},
...overrides
};
}
function render(overrides = {}) {
const props = generateDefaults(overrides);
const component = shallow(<DebugLine.WrappedComponent {...props} />);
return { component, props };
}
describe("DebugLine Component", () => {
describe("mount", () => {
it("should keep the debugExpression state", async () => {
const { component } = render();
expect(component.state().debugExpression).toBeDefined();
expect(component.state().debugExpression.clear).toBeDefined();
});
});
describe("unmount", () => {
it("should remove the debug line", async () => {
const { component } = render();
component.unmount();
expect(mockGetDocument.removeLineClass).toHaveBeenCalled();
});
it("should clear the debug line", async () => {
const { component } = render();
component.unmount();
expect(mockGetDocument.removeLineClass).toHaveBeenCalled();
});
});
describe("update", () => {
const selectedLocation = {
location: {
sourceId: "x",
line: 1
}
};
it("should remove the old debug line", async () => {
const { component } = render();
component.setProps({ selectedLocation });
expect(mockGetDocument.removeLineClass).toHaveBeenCalled();
});
it("should clear the previous debugExpression", async () => {
const { component } = render();
component.setState({ debugExpression: { clear: jest.fn() } });
const previousState = component.state();
component.setProps({ selectedLocation });
expect(previousState.debugExpression.clear).toHaveBeenCalled();
});
it("should add a new line and debugExpression", async () => {
const { component } = render();
const previousState = component.state();
component.setProps({ selectedLocation });
const currentState = component.state();
expect(currentState.debugExpression).toBeDefined();
expect(currentState.debugExpression.clear).toBeDefined();
expect(previousState.debugExpression).not.toBe(
currentState.debugExpression
);
});
});
});