Closed bahmutov closed 7 years ago
How to support multiple arguments, like this?
function sum(a, b) { return a + b }
it('adds numbers', () => {
snap(sum, [[1, 2], [2, -4], [2, 3]])
})
// maybe spread the arguments?
function sum(a, b) { return a + b }
it('adds numbers', () => {
snap(sum, [1, 2], [2, -4], [2, 3])
})
// and for unary function
it('finds primes', () => {
snap(isPrime, 1, 2, 3, 4, 5, 6)
})
How to describe multiple properties, like the multiple chained assertions? From https://github.com/mikec/sazerac-example/blob/master/todos/src/reducers/todos.spec.js
given([], {
type: 'ADD_TODO',
text: 'Run the tests',
id: 0
})
.describe('when state is empty and a todo is added')
.assert('should add the todo and set `id` property', (state) => {
expect(state[0].id).toEqual(0)
})
.assert('should add the todo and set `text` property', (state) => {
expect(state[0].text).toEqual('Run the tests')
})
.assert('should set completed:false on the added todo', (state) => {
expect(state[0].completed).toEqual(false)
})
.assert('should add only one todo', (state) => {
expect(state.length).toEqual(1)
})
this could be just single result object with evolved properties.
See https://github.com/bahmutov/snap-shot-jest-test#data-driven-testing and https://hackernoon.com/sazerac-data-driven-testing-for-javascript-e3408ac29d8c#.3qht1jpdi and https://github.com/mikec/sazerac
Good rule is two find two arguments, first being a function and a list of inputs second.