Skip to content

Instantly share code, notes, and snippets.

@phatnguyenuit
Created October 21, 2021 17:05
Show Gist options
  • Save phatnguyenuit/b5eecb0e1d0dff158600134d29aa3ab8 to your computer and use it in GitHub Desktop.
Save phatnguyenuit/b5eecb0e1d0dff158600134d29aa3ab8 to your computer and use it in GitHub Desktop.
Prevent code duplication when writing unit tests with Jest .each - duplication test cases
import { toKebabCase } from './utils';
describe('toKebabCase', () => {
it('should work from empty string', () => {
expect(toKebabCase('')).toEqual('');
});
it('should return "my-example" when given "my_example"', () => {
expect(toKebabCase('my_example')).toEqual('my-example');
});
it('should return "another-example" when given "Another-Example"', () => {
expect(toKebabCase('Another-Example')).toEqual('another-example');
});
it('should return "another-example" when given "anotherExample"', () => {
expect(toKebabCase('anotherExample')).toEqual('another-example');
});
it('should return "another-example-1-2-3" when given "anotherExample123"', () => {
expect(toKebabCase('anotherExample123')).toEqual('another-example-1-2-3');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment