-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rong Sen Ng (motss) <wes.ngrongsen@gmail.com>
- Loading branch information
Showing
1 changed file
with
29 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,43 @@ | ||
import { expect } from '@open-wc/testing'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import { splitString } from '../../helpers/split-string'; | ||
import { messageFormatter } from '../test-utils/message-formatter'; | ||
|
||
describe(splitString.name, () => { | ||
const str = 'hello, world, everyone'; | ||
const expected = str.split(/,\s*/); | ||
|
||
type CaseSplitString = [ | ||
source: string, | ||
expected: string[] | ||
]; | ||
const casesSplitString: CaseSplitString[] = [ | ||
['', []], | ||
[str, expected], | ||
]; | ||
casesSplitString.forEach((a) => { | ||
it( | ||
messageFormatter('splits string (%s)', a), | ||
() => { | ||
const [testSource, expected] = a; | ||
const result = splitString(testSource); | ||
|
||
expect(result).deep.equal(expected); | ||
} | ||
); | ||
it.each<{ | ||
$_value: string[]; | ||
source: string; | ||
}>([ | ||
{ | ||
$_value: [], | ||
source: '', | ||
}, | ||
{ | ||
$_value: expected, | ||
source: str, | ||
}, | ||
])('splits string ($source)', ({ | ||
$_value, | ||
source, | ||
}) => { | ||
const result = splitString(source); | ||
|
||
expect(result).toEqual($_value); | ||
}); | ||
|
||
type CaseSplitStringWithOptionalCallbackAndSeparator = [ | ||
separator?: RegExp | ||
]; | ||
const casesSplitStringWithOptionalCallback: CaseSplitStringWithOptionalCallbackAndSeparator[] = [ | ||
it.each<[separator?: RegExp]>([ | ||
[], | ||
[/,\s/], | ||
]; | ||
casesSplitStringWithOptionalCallback.forEach((a) => { | ||
it( | ||
messageFormatter('splits string with optional callback and optional separator (%s)', a), | ||
() => { | ||
const [testSeparator] = a; | ||
|
||
const result = splitString<[string]>( | ||
str, | ||
(n) => [n], | ||
testSeparator | ||
); | ||
|
||
expect(result).deep.equal(expected.map(n => [n])); | ||
} | ||
); | ||
])('splits string with optional callback and optional separator (%s)', (separator) => { | ||
const result = splitString<[string]>( | ||
str, | ||
(n) => [n], | ||
separator | ||
); | ||
|
||
expect(result).toEqual(expected.map(n => [n])); | ||
}); | ||
|
||
}); |