Skip to content
This repository was archived by the owner on Feb 18, 2021. It is now read-only.

Commit 62b6050

Browse files
committed
test(settings): refactor test
1 parent 84dadc0 commit 62b6050

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

src/renderer/components/Settings/index.test.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,21 @@ import sinon from 'sinon';
66
import Settings from './';
77

88
describe('components/Settings', () => {
9-
it('should display a checkbox for dark theme', () => {
10-
const context = shallow(<Settings
11-
darkTheme={true}
12-
onChangeSetting={sinon.spy()}
13-
/>);
9+
const defaultProps = {
10+
darkTheme: false,
11+
onChangeSetting: () => null,
12+
};
1413

15-
expect(context.find('input[name="darkTheme"]').length).to.equal(1);
16-
});
17-
18-
it('should call onUpdateSetting upon changing a setting', () => {
14+
it('should call onChangeSetting upon toggling checkbox for dark theme', () => {
1915
const onChangeSetting = sinon.spy();
20-
const context = shallow(<Settings
21-
darkTheme={true}
22-
onChangeSetting={onChangeSetting}
23-
/>);
16+
const wrapper = shallow(<Settings {...defaultProps} onChangeSetting={onChangeSetting} />);
2417

25-
context.find('input').forEach(input => {
26-
const event = {
27-
target: {
28-
name: input.prop('name'),
29-
checked: true,
30-
},
31-
};
32-
input.simulate('change', event);
18+
const name = 'darkTheme';
19+
const checked = true;
20+
const event = { target: { name, checked } };
21+
wrapper.find(`input[name="${name}"]`).simulate('change', event);
3322

34-
expect(onChangeSetting).to.have.been.called;
35-
});
23+
expect(onChangeSetting).to.have.been.calledWith(name, checked);
3624
});
25+
3726
});

0 commit comments

Comments
 (0)