Skip to content

Commit ac6687f

Browse files
Merge pull request #13 from wimpyprogrammer/feature/cleanup-tests
Clean-up tests
2 parents dc4e33e + 67cc218 commit ac6687f

File tree

3 files changed

+30
-55
lines changed

3 files changed

+30
-55
lines changed

demo/src/utils/wordList.spec.ts

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,48 @@
11
import { parseString, WhitespaceHandling } from './wordList';
22

3-
interface TestCase {
4-
delimiter: string;
5-
inputString: string;
6-
}
7-
83
const { Preserve, TrimLeadingAndTrailing } = WhitespaceHandling;
94

105
describe('parseString', () => {
11-
it('returns an empty array when input string is empty', () => {
12-
function testInput(input: string): void {
13-
const wordList = parseString(input, ',', Preserve);
6+
it.each(['', null, undefined])(
7+
'returns an empty array when input string is %p',
8+
input => {
9+
const wordList = parseString(input as string, ',', Preserve);
1410
expect(wordList).toEqual([]);
1511
}
12+
);
1613

17-
['', null, undefined].forEach(val => testInput(val as string));
18-
});
19-
20-
it('returns entire input string in array when delimiter is empty', () => {
21-
function testDelimiter(delimiter: string): void {
14+
it.each(['', null, undefined])(
15+
'returns entire input string in array when delimiter is %p',
16+
testDelimiter => {
17+
const delimiter = testDelimiter as string;
2218
const wordList = parseString(' some input string ', delimiter, Preserve);
2319
expect(wordList).toEqual([' some input string ']);
2420
}
21+
);
2522

26-
['', null, undefined].forEach(val => testDelimiter(val as string));
27-
});
28-
29-
it('returns entire input string in array when delimiter is not present in input string', () => {
30-
function testDelimiter(delimiter: string): void {
23+
it.each([',', '\n', '\t'])(
24+
'returns entire input string in array when delimiter %p is not present in input string',
25+
delimiter => {
3126
const wordList = parseString(' some input string ', delimiter, Preserve);
3227
expect(wordList).toEqual([' some input string ']);
3328
}
34-
35-
[',', '\n', '\t'].forEach(testDelimiter);
36-
});
37-
38-
it('splits input string by delimiter', () => {
39-
const expectedResult = ['foo', 'Bar', ' b@z '];
40-
const testCases: TestCase[] = [
41-
{ delimiter: ',', inputString: 'foo,Bar, b@z ' },
42-
{ delimiter: '\t', inputString: 'foo Bar b@z ' },
43-
{ delimiter: 'aaa', inputString: 'fooaaaBaraaa b@z ' },
44-
];
45-
46-
function testSplit({ delimiter, inputString }: TestCase): void {
47-
const wordList = parseString(inputString, delimiter, Preserve);
48-
expect(wordList).toEqual(expectedResult);
49-
}
50-
51-
testCases.forEach(testSplit);
29+
);
30+
31+
it.each([
32+
['foo,Bar, b@z ', ','],
33+
['foo Bar b@z ', '\t'],
34+
['fooaaaBaraaa b@z ', 'aaa'],
35+
])('splits input string %p by delimiter %p', (inputString, delimiter) => {
36+
const wordList = parseString(inputString, delimiter, Preserve);
37+
expect(wordList).toEqual(['foo', 'Bar', ' b@z ']);
5238
});
5339

54-
it('splits input string by whitespace delimiter', () => {
55-
const expectedResult = ['foo', 'Bar', 'b@z', ''];
56-
const testCases: TestCase[] = [
57-
{ delimiter: ' ', inputString: 'foo Bar b@z ' },
58-
{ delimiter: ' ', inputString: 'foo Bar b@z ' },
59-
];
60-
61-
function testSplit({ delimiter, inputString }: TestCase): void {
62-
const wordList = parseString(inputString, delimiter, Preserve);
63-
expect(wordList).toEqual(expectedResult);
64-
}
65-
66-
testCases.forEach(testSplit);
40+
it.each([
41+
['foo Bar b@z ', ' '],
42+
['foo Bar b@z ', ' '],
43+
])('splits input string %p by delimiter %p', (inputString, delimiter) => {
44+
const wordList = parseString(inputString, delimiter, Preserve);
45+
expect(wordList).toEqual(['foo', 'Bar', 'b@z', '']);
6746
});
6847

6948
it('splits multiline input string by newline delimiter', () => {

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"@types/jest-when": "^2.7.0",
5353
"@typescript-eslint/eslint-plugin": "^2.2.0",
5454
"@typescript-eslint/parser": "^2.2.0",
55-
"codecov": "^3.6.1",
5655
"eslint": "6.1.0",
5756
"eslint-config-airbnb-base": "14.0.0",
5857
"eslint-config-prettier": "^6.3.0",
@@ -61,12 +60,11 @@
6160
"eslint-plugin-jest": "^22.17.0",
6261
"husky": "^0.14.3",
6362
"jest": "^26.0.0",
64-
"jest-when": "^2.7.0",
63+
"jest-when": "^3.1.0",
6564
"npm-run-all": "^4.1.5",
6665
"prettier": "^1.13.7",
6766
"pretty-quick": "^1.6.0",
68-
"regenerator-runtime": "^0.13.3",
69-
"regex-to-strings": "^1.0.0",
67+
"regex-to-strings": "^2.0.1",
7068
"rimraf": "^2.6.2",
7169
"ts-jest": "^26.4.4",
7270
"ts-loader": "^6.1.0",

src/utils/pattern.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'regenerator-runtime/runtime';
2-
31
import { expandAll } from 'regex-to-strings';
42
import { CharTrie } from '../types/charTrie';
53
import { build } from './pattern';

0 commit comments

Comments
 (0)