Last active
February 5, 2018 16:54
-
-
Save zebulonj/af880f7500ee5e65e48034698e9008e5 to your computer and use it in GitHub Desktop.
Clean specs based on iteration inspector.
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 test from 'tape'; | |
import { query } from './store'; | |
import { summarize } from './model'; | |
// This could be removed to a helper library... you'd never have to look at it if you didn't want. | |
const inspectIteration = assert => steps => iterator => { | |
let result; | |
steps.forEach( ( def, index ) => { | |
const step = iterator.next( result ); | |
assert.equal( step.done, !!def.done, `Step ${ index + 1 }: Completion status should be correctly reflected.` ); | |
assert.deepEqual( step.value, def.value, `Step ${ index + 1 }: The expected output should be received.` ); | |
result = def.result; | |
}) | |
} | |
// This is the whole damn test. Isn't it easy to read? | |
test( "...summarize()", assert => { | |
const user = {}; | |
const form_id = 'form_02'; | |
const iter = summarize( user, form_id ); | |
const steps = [ | |
{ | |
value: { fn: query, params: ['SELECT status, COUNT( status ) AS count FROM submissions WHERE form_id = ? GROUP BY status', form_id] }, | |
result: [ | |
{ status: 'draft', count: '12' } | |
] | |
}, | |
{ | |
value: [ | |
{ status: 'draft', count: '12' } | |
], | |
done: true | |
} | |
]; | |
// This signature is kindof dumb... no currying called for here. Limited likelihood for reuse in an isolated test. | |
// Could just as well be inspectIteration( assert, steps, iter ); | |
inspectIteration( assert )( steps )( iter ); | |
assert.end(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment