Last active
August 17, 2020 18:16
-
-
Save diegolameira/6e33a104c409a5e432ae3c44f92570c5 to your computer and use it in GitHub Desktop.
[ Jest Each ] https://itnext.io/reduce-unit-tests-boilerplate-with-jests-each-syntax-f5e48828437f #jest #development #tdd
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
import React from 'react'; | |
import { shallow } from 'enzyme'; | |
import Button from './Button'; | |
let props; | |
beforeEach(() => { | |
props = { | |
isPrimary: false, | |
isDanger: false, | |
isSuccess: false, | |
}; | |
}); | |
describe('test Button component', () => { | |
it.each` | |
propName | propValue | className | result | |
${'isPrimary'} | ${true} | ${'is-primary'} | ${true} | |
${'isDanger'} | ${true} | ${'is-danger'} | ${true} | |
${'isSuccess'} | ${true} | ${'is-success'} | ${true} | |
`('should have class $className when prop $propName is equal to $propValue', ({propName, propValue, className, result}) => { | |
props = { ...props, [propName]: propValue }; | |
const enzymeWrapper = shallow(<Button {...props} />); | |
expect(enzymeWrapper.hasClass(className)).toEqual(result); | |
}); | |
it.each` | |
propName | propValue | className | result | |
${'isPrimary'} | ${false} | ${'is-primary'} | ${false} | |
${'isDanger'} | ${false} | ${'is-danger'} | ${false} | |
${'isSuccess'} | ${false} | ${'is-success'} | ${false} | |
`('should have not class $className when prop $propName is equal to $propValue', ({propName, propValue, className, result}) => { | |
props = { ...props, [propName]: propValue }; | |
const enzymeWrapper = shallow(<Button {...props} />); | |
expect(enzymeWrapper.hasClass(className)).toEqual(result); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
God