Created
February 15, 2018 11:57
-
-
Save AshCoolman/4582b2811733c8a29b38dca8fb002460 to your computer and use it in GitHub Desktop.
Label to help with jest snapshots
This file contains hidden or 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
// Jests dont write to file in chron order, prefix with number helps | |
let count = 0; | |
const label = (tmpl, ...val) => { | |
val.reverse(); | |
return `${ | |
count++ // eslint-disable-line | |
}. ${ | |
tmpl.reduce((p, c) => p + c + (val.length ? val.pop() : ''), '') | |
}`; | |
}; | |
const labelReset = (...args) => { | |
count = 0; | |
return label(...args); | |
}; | |
export { label, labelReset }; | |
// test | |
import { label, labelReset } from './'; | |
describe('ofs-dev-tools/src/label', () => { | |
it('should have expected output', () => { | |
expect([ | |
label`the start A:${'a'} B:${'b'}...`, | |
label`...done C:${'c'} D:${'d'}`, | |
labelReset`new start...`, | |
label`...done`, | |
]).toMatchSnapshot(); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment