KnobManager.test.js
2.11 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
import { shallow } from 'enzyme'; // eslint-disable-line
import KnobManager from './KnobManager';
describe('KnobManager', () => {
describe('knob()', () => {
describe('when the knob is present in the knobStore', () => {
const testManager = new KnobManager();
beforeEach(() => {
testManager.knobStore = {
set: jest.fn(),
get: () => ({
defaultValue: 'default value',
value: 'current value',
name: 'foo',
}),
};
});
it('should return the existing knob value when defaults match', () => {
const defaultKnob = {
name: 'foo',
value: 'default value',
};
const knob = testManager.knob('foo', defaultKnob);
expect(knob).toEqual('current value');
expect(testManager.knobStore.set).not.toHaveBeenCalled();
});
it('should return the new default knob value when default has changed', () => {
const defaultKnob = {
name: 'foo',
value: 'changed default value',
};
testManager.knob('foo', defaultKnob);
const newKnob = {
...defaultKnob,
defaultValue: defaultKnob.value,
};
expect(testManager.knobStore.set).toHaveBeenCalledWith('foo', newKnob);
});
});
describe('when the knob is not present in the knobStore', () => {
const testManager = new KnobManager();
beforeEach(() => {
testManager.knobStore = {
set: jest.fn(),
get: jest.fn(),
};
testManager.knobStore.get
.mockImplementationOnce(() => undefined)
.mockImplementationOnce(() => 'normal value');
});
it('should return the new default knob value when default has changed', () => {
const defaultKnob = {
name: 'foo',
value: 'normal value',
};
testManager.knob('foo', defaultKnob);
const newKnob = {
...defaultKnob,
defaultValue: defaultKnob.value,
};
expect(testManager.knobStore.set).toHaveBeenCalledWith('foo', newKnob);
});
});
});
});