Skip to content

Instantly share code, notes, and snippets.

@Saturate
Created March 22, 2019 13:47
Show Gist options
  • Save Saturate/aaa9546d06c9e1f8d379a91f6bd7bb44 to your computer and use it in GitHub Desktop.
Save Saturate/aaa9546d06c9e1f8d379a91f6bd7bb44 to your computer and use it in GitHub Desktop.
When you use redux, you might have an actions keys file, a common error is having two const export the same thing. This will test for that, and maybe make your coverage 100%!
import * as actionKeys from './action-keys';
describe('action keys', () => {
it('should have a unique string for each key', () => {
let uniq = Object.keys(actionKeys)
.map(objKey => {
return { count: 1, name: actionKeys[objKey] };
})
.reduce((a, b) => {
a[b.name] = (a[b.name] || 0) + b.count;
return a;
}, {});
const duplicates = Object.keys(uniq).filter(a => uniq[a] > 1);
expect(duplicates).toHaveLength(0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment