Commit 43d74305 authored by Scott Hampton's avatar Scott Hampton

Use `it.each` for util spec

Utilize `it.each` to make a cleaner spec file for
the util function.
parent ce6d8bae
......@@ -2,44 +2,16 @@ import { formatFilePath, formattedTime } from '~/pipelines/stores/test_reports/u
describe('Test reports utils', () => {
describe('formatFilePath', () => {
describe('when file string starts with "./"', () => {
it('should return the file string without the beginning "./"', () => {
const result = formatFilePath('./test.js');
expect(result).toBe('test.js');
});
});
describe('when file string starts with "/"', () => {
it('should return the file string without the beginning "/"', () => {
const result = formatFilePath('/test.js');
expect(result).toBe('test.js');
});
});
describe('when file string starts with more than one "/"', () => {
it('should return the file string without any of the beginning "/"', () => {
const result = formatFilePath('.//////////////test.js');
expect(result).toBe('test.js');
});
});
describe('when file string starts without either "." or "/"', () => {
it('should return the file string without change', () => {
const result = formatFilePath('test.js');
expect(result).toBe('test.js');
});
});
describe('when file string contains but does not start with "./"', () => {
it('should return the file string without change', () => {
const result = formatFilePath('mock/path./test.js');
expect(result).toBe('mock/path./test.js');
});
it.each`
file | expected
${'./test.js'} | ${'test.js'}
${'/test.js'} | ${'test.js'}
${'.//////////////test.js'} | ${'test.js'}
${'test.js'} | ${'test.js'}
${'mock/path./test.js'} | ${'mock/path./test.js'}
${'./mock/path./test.js'} | ${'mock/path./test.js'}
`('should format $file to be $expected', ({ file, expected }) => {
expect(formatFilePath(file)).toBe(expected);
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment