- Use better error messages with more context. - Unify their validation logic and share tests. - Validate also type of the name. - Refactor node (Script/Category) parser tests for easier future changes and cleaner test code (using `TestBuilder` to do dirty work in unified way). - Add more tests. Custom `Error` properties are compared manually due to `chai` not supporting deep equality checks (chaijs/chai#1065, chaijs/chai#1405).
71 lines
1.7 KiB
TypeScript
71 lines
1.7 KiB
TypeScript
export function itEachAbsentStringValue(runner: (absentValue: string) => void): void {
|
|
itEachAbsentTestCase(AbsentStringTestCases, runner);
|
|
}
|
|
|
|
export function itEachAbsentObjectValue(
|
|
runner: (absentValue: AbsentObjectType) => void,
|
|
): void {
|
|
itEachAbsentTestCase(AbsentObjectTestCases, runner);
|
|
}
|
|
|
|
export function itEachAbsentCollectionValue<T>(runner: (absentValue: []) => void): void {
|
|
itEachAbsentTestCase(getAbsentCollectionTestCases<T>(), runner);
|
|
}
|
|
|
|
export function itEachAbsentTestCase<T>(
|
|
testCases: readonly IAbsentTestCase<T>[],
|
|
runner: (absentValue: T) => void,
|
|
): void {
|
|
for (const testCase of testCases) {
|
|
it(`given "${testCase.valueName}"`, () => {
|
|
runner(testCase.absentValue);
|
|
});
|
|
}
|
|
}
|
|
|
|
export const AbsentObjectTestCases: readonly IAbsentTestCase<AbsentObjectType>[] = [
|
|
{
|
|
valueName: 'undefined',
|
|
absentValue: undefined,
|
|
},
|
|
{
|
|
valueName: 'null',
|
|
absentValue: null,
|
|
},
|
|
];
|
|
|
|
export const AbsentStringTestCases: readonly IAbsentStringCase[] = [
|
|
{
|
|
valueName: 'empty',
|
|
absentValue: '',
|
|
},
|
|
...AbsentObjectTestCases,
|
|
];
|
|
|
|
export function getAbsentCollectionTestCases<T>(): readonly IAbsentCollectionCase<T>[] {
|
|
return [
|
|
...AbsentObjectTestCases,
|
|
{
|
|
valueName: 'empty',
|
|
absentValue: new Array<T>(),
|
|
},
|
|
];
|
|
}
|
|
|
|
type AbsentObjectType = undefined | null;
|
|
|
|
interface IAbsentTestCase<T> {
|
|
readonly valueName: string;
|
|
readonly absentValue: T;
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
interface IAbsentStringCase extends IAbsentTestCase<string> {
|
|
// Marker interface
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
interface IAbsentCollectionCase<T> extends IAbsentTestCase<T[]> {
|
|
// Marker interface
|
|
}
|