-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ffe-checkbox-react): Migrate tests to jest
- Loading branch information
Kristofer Selbekk
committed
Feb 22, 2018
1 parent
ad31b46
commit f5935ff
Showing
5 changed files
with
128 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"overrides": [ | ||
{ | ||
"files": [ "src/**/*.spec.js"], | ||
"env": { | ||
"jest": true | ||
} | ||
} | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
|
||
import Checkbox from './Checkbox'; | ||
|
||
const getWrapper = props => shallow(<Checkbox {...props} />); | ||
|
||
describe('<Checkbox />', () => { | ||
it('should render a input', () => { | ||
const wrapper = getWrapper(); | ||
expect(wrapper.find('input').exists()).toBe(true); | ||
}); | ||
|
||
it('should call onChange when clicked', () => { | ||
const spy = jest.fn(); | ||
const wrapper = getWrapper({ onChange: spy }); | ||
|
||
wrapper.find('input').simulate('change'); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call onChange with the correct parameter', () => { | ||
const mockEvent = { target: { value: true } }; | ||
const spy = jest.fn(); | ||
|
||
const wrapper = getWrapper({ onChange: spy }); | ||
|
||
wrapper.find('input').simulate('change', mockEvent); | ||
|
||
expect(spy.mock.calls[0][0]).toBe(mockEvent); | ||
}); | ||
|
||
it('should render a default value if passed', () => { | ||
let wrapper = getWrapper(); | ||
|
||
expect(wrapper.find('input').prop('checked')).toBe(undefined); | ||
|
||
wrapper = getWrapper({ checked: true }); | ||
|
||
expect(wrapper.find('input').prop('checked')).toBe(true); | ||
}); | ||
|
||
it('should apply the same id to <label> and <input>', () => { | ||
const wrapper = getWrapper({ name: 'Some text goes here' }); | ||
|
||
expect(wrapper.find('label').prop('htmlFor')).toBe( | ||
wrapper.find('input').prop('id'), | ||
); | ||
}); | ||
|
||
it('should support noMargins', () => { | ||
const wrapper = getWrapper({ noMargins: false }); | ||
|
||
expect(wrapper.find('.ffe-checkbox--no-margin').exists()).toBe(false); | ||
|
||
wrapper.setProps({ noMargins: true }); | ||
|
||
expect(wrapper.find('.ffe-checkbox--no-margin').exists()).toBe(true); | ||
}); | ||
|
||
it('should support inline', () => { | ||
const wrapper = getWrapper(); | ||
|
||
expect(wrapper.find('.ffe-checkbox--inline').exists()).toBe(true); | ||
|
||
wrapper.setProps({ inline: false }); | ||
|
||
expect(wrapper.find('.ffe-checkbox--inline').exists()).toBe(false); | ||
|
||
wrapper.setProps({ inline: true }); | ||
|
||
expect(wrapper.find('.ffe-checkbox--inline').exists()).toBe(true); | ||
}); | ||
|
||
it('should support invalid', () => { | ||
const wrapper = getWrapper({ invalid: false }); | ||
|
||
expect(wrapper.find('input').prop('aria-invalid')).toBe('false'); | ||
|
||
wrapper.setProps({ invalid: true }); | ||
|
||
expect(wrapper.find('input').prop('aria-invalid')).toBe('true'); | ||
}); | ||
|
||
it('setting "aria-invalid" should override "invalid"', () => { | ||
const wrapper = getWrapper({ invalid: true, 'aria-invalid': 'false' }); | ||
|
||
expect(wrapper.find('input').prop('aria-invalid')).toBe('false'); | ||
|
||
wrapper.setProps({ invalid: false, 'aria-invalid': 'true' }); | ||
|
||
expect(wrapper.find('input').prop('aria-invalid')).toBe('true'); | ||
}); | ||
|
||
it('should set arbitrary props (rest) on input', () => { | ||
const wrapper = getWrapper({ | ||
name: 'checkbox', | ||
iDontReallyDoAnything: 'false', | ||
tabIndex: -1, | ||
}); | ||
|
||
expect(wrapper.find('input').prop('name')).toBe('checkbox'); | ||
expect(wrapper.find('input').prop('iDontReallyDoAnything')).toBe( | ||
'false', | ||
); | ||
expect(wrapper.find('input').prop('tabIndex')).toBe(-1); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.