This repository was archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-multi-context.spec.js
136 lines (114 loc) · 2.75 KB
/
create-multi-context.spec.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import Enzyme, { mount, shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import createMultiContext from '../index';
Enzyme.configure({ adapter: new Adapter() });
describe('createMultiContext', () => {
let MultiContext = null;
beforeEach(() => {
MultiContext = createMultiContext({ d: true });
});
it('should render without crashing', () => {
shallow(<MultiContext />);
});
it.skip('should not render contexts without getters/setters', () => {
const multiContext = shallow(<MultiContext />);
expect(multiContext.find('Context').length).toBe(0);
});
// Set
describe('set', () => {
it('should accept an object', () => {
expect(() => {
shallow(<MultiContext set={{ a: 1 }} />);
}).not.toThrowError();
});
});
// Get
describe('get', () => {
it('should accept an array and a render prop', () => {
shallow(<MultiContext set={{ a: 1 }} />);
expect(() => {
shallow(
<MultiContext
children={() => null}
get={[ 'a' ]}
/>
);
}).not.toThrowError();
});
it('should require a render prop', () => {
shallow(<MultiContext set={{ a: 1 }} />);
expect(() => {
shallow(
<MultiContext
children={true}
get={[ 'a' ]}
/>
);
}).toThrowError();
expect(() => {
shallow(
<MultiContext
children={1}
get={[ 'a' ]}
/>
);
}).toThrowError();
expect(() => {
shallow(
<MultiContext
children="children"
get={[ 'a' ]}
/>
);
}).toThrowError();
});
it('should execute the render prop', () => {
let value = null;
mount(
<MultiContext set={{ a: 1 }}>
<MultiContext get={[ 'a' ]}>
{a => {
value = a;
return null;
}}
</MultiContext>
</MultiContext>
);
expect(value).toBe(1);
});
});
// Defaults
describe('default', () => {
it('should accept default parameter', () => {
let value = null;
mount(
<MultiContext
children={d => {
value = d;
return null;
}}
get={[ 'd' ]}
/>
);
expect(value).toBe(true);
});
});
// Set + Get
describe('set + get', () => {
it('should not get what was just set', () => {
let value = null;
mount(
<MultiContext
children={d => {
value = d;
return null;
}}
get={[ 'd' ]}
set={{ d: false }}
/>
);
expect(value).toBe(true);
});
});
});