Skip to content

Instantly share code, notes, and snippets.

@AshCoolman
Created February 15, 2018 11:57
Show Gist options
  • Save AshCoolman/4582b2811733c8a29b38dca8fb002460 to your computer and use it in GitHub Desktop.
Save AshCoolman/4582b2811733c8a29b38dca8fb002460 to your computer and use it in GitHub Desktop.
Label to help with jest snapshots
// 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