Skip to content

Commit 8fc248c

Browse files
committed
Simplifies method spies
1 parent e0dfc23 commit 8fc248c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Node/tests/index.test.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ describe('<Node />', () => {
2323
onClick: () => {},
2424
};
2525

26+
27+
jest.spyOn(Node.prototype, 'applyTransform');
28+
2629
// Clear method spies on prototype after each test
2730
afterEach(() => jest.clearAllMocks());
2831

32+
2933
it('has the correct `id` attribute value', () => {
3034
const renderedComponent = shallow(
3135
<Node {...mockProps} />
@@ -34,6 +38,7 @@ describe('<Node />', () => {
3438
expect(renderedComponent.find('g').prop('id')).toBe(nodeData.id);
3539
});
3640

41+
3742
it('applies correct base className if `nodeData._children` is defined', () => {
3843
const noChildrenComponent = shallow(
3944
<Node {...mockProps} />
@@ -49,6 +54,7 @@ describe('<Node />', () => {
4954
expect(withChildrenComponent.prop('className')).toBe('nodeBase');
5055
});
5156

57+
5258
it('applies correct <circle> style prop if `nodeData._children` is defined', () => {
5359
const leafCircleStyle = { fill: 'blue' };
5460
const circleStyle = { fill: 'green' };
@@ -72,6 +78,7 @@ describe('<Node />', () => {
7278
expect(withChildrenComponent.find('circle').prop('style')).toBe(circleStyle);
7379
});
7480

81+
7582
it('applies correct `transform` prop based on its `orientation`', () => {
7683
const horizontalTransform = `translate(${nodeData.parent.y},${nodeData.parent.x})`;
7784
const verticalTransform = `translate(${nodeData.parent.x},${nodeData.parent.y})`;
@@ -88,6 +95,7 @@ describe('<Node />', () => {
8895
expect(verticalComponent.find('g').prop('transform')).toBe(verticalTransform);
8996
});
9097

98+
9199
it('should take an `onClick` prop', () => {
92100
const renderedComponent = shallow(
93101
<Node
@@ -99,6 +107,7 @@ describe('<Node />', () => {
99107
expect(renderedComponent.prop('onClick')).toBeDefined();
100108
});
101109

110+
102111
it('handles click events and passes its nodeId to onClick handler', () => {
103112
const onClickSpy = jest.fn();
104113
const renderedComponent = shallow(
@@ -112,6 +121,7 @@ describe('<Node />', () => {
112121
expect(onClickSpy).toHaveBeenCalledWith(nodeData.id);
113122
});
114123

124+
115125
it('maps each `props.secondaryLabels` to a <tspan> element', () => {
116126
const fixture = { keyA: 'valA', keyB: 'valB' };
117127
const renderedComponent = shallow(
@@ -132,6 +142,7 @@ describe('<Node />', () => {
132142
).toBe(1);
133143
});
134144

145+
135146
it('mutates the node\'s `y` property according to `depthFactor`, when specified', () => {
136147
const depthFactor = 100;
137148
const expectedY = nodeData.depth * depthFactor;
@@ -146,8 +157,8 @@ describe('<Node />', () => {
146157
expect(renderedComponent.prop('transform')).toBe(`translate(${nodeData.parent.x},${expectedY})`);
147158
});
148159

160+
149161
it('applies its own x/y coords on `transform` once mounted', () => {
150-
jest.spyOn(Node.prototype, 'applyTransform');
151162
const fixture = `translate(${nodeData.y},${nodeData.x})`;
152163
const renderedComponent = mount(
153164
<Node
@@ -158,8 +169,9 @@ describe('<Node />', () => {
158169
expect(renderedComponent.instance().applyTransform).toHaveBeenCalledWith(fixture);
159170
});
160171

172+
161173
it('updates its transform attribute if either the `x` or `y` prop changes', () => {
162-
jest.spyOn(Node.prototype, 'applyTransform');
174+
// jest.spyOn(Node.prototype, 'applyTransform');
163175
const updatedProps = {
164176
...mockProps,
165177
nodeData: {

0 commit comments

Comments
 (0)