Skip to content

Instantly share code, notes, and snippets.

@kamilogorek
Created February 10, 2017 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kamilogorek/ba356105a499597c5f9a4e015886947b to your computer and use it in GitHub Desktop.
Save kamilogorek/ba356105a499597c5f9a4e015886947b to your computer and use it in GitHub Desktop.
test(isPrime, () => {
given(1).expect(false)
given(2).expect(true)
given(3).expect(true)
given(4).expect(false)
})
// vs.
describe('isPrime()', () => {
it('handles integers correctly', () => {
expect(isPrime(1)).toBe(false)
expect(isPrime(2)).toBe(true)
expect(isPrime(3)).toBe(true)
expect(isPrime(4)).toBe(false)
})
})
////////////////
test(ProductComponent, () => {
forCases(
given({}),
given({ price: '1.11', inventory: '111' }),
given({ title: 'p1', inventory: '111' }),
given({ title: 'p1', price: '1.11' })
)
.assert('should render `error` class', (p) => {
expect(p.product.hasClass('error')).toBe(true)
})
.assert('should display error message', (p) => {
expect(p.errorMessage.text()).toMatch(/Please enter all product info/)
})
.assert('should not display success message', (p) => {
expect(p.successMessage.exists()).toBe(false)
})
})
// vs.
describe('ProductComponent', () => {
const cases = [
{},
{ price: '1.11', inventory: '111' },
{ title: 'p1', inventory: '111' },
{ title: 'p1', price: '1.11' }
]
cases.forEach((input) => {
const p = ProductComponent(input)
it('should render `error` class', (p) => expect(p.product.hasClass('error')).toBe(true))
it('should display error message', (p) => expect(p.errorMessage.text()).toMatch(/Please enter all product info/))
it('should not display success message', (p) => expect(p.successMessage.exists()).toBe(false))
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment