[jasmine-data-provider] definitions for undocumented behaviour (#29835)

* improve type defs

* undocumented types

* change type

* satisfy the linter
This commit is contained in:
Tomek Łaziuk 2018-10-18 17:58:14 +02:00 committed by Sheetal Nandi
parent 724810601f
commit cc7d8d21ae
2 changed files with 41 additions and 2 deletions

View File

@ -2,13 +2,15 @@
// Project: https://github.com/MortalFlesh/jasmine-data-provider
// Definitions by: Tomek Łaziuk <https://github.com/tlaziuk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
// TypeScript Version: 2.8
declare function using<T extends any[]>(values: using.ValueType<T[]>, func: (...data: Array<using.ArrayFuncArgType<T>>) => void): void;
declare function using<T>(values: using.ValueType<T[]>, func: (data: T) => void): void;
declare function using<T, K extends keyof T>(values: using.ValueType<T>, func: (data: T[K], description: K) => void): void;
declare function using<T>(values: using.ValueType<Record<string, T>>, func: (data: T, description: string) => void): void;
declare namespace using {
type ValueType<T> = T | (() => T);
type ArrayFuncArgType<T> = T extends Array<infer U> ? U : never;
}
export = using;

View File

@ -46,3 +46,40 @@ describe('My fantastic test', () => {
});
});
});
// undocumented behaviour
describe(`Ugh, I don't know if this one works`, () => {
using([[6, 3, 9], [8, 1, 10]], (a, b, expected) => {
it('should calc with operator +', () => {
const result = calculator.calc(a, b, '+');
expect(result).toEqual(expected);
});
});
});
// TypeScript-specific tests
describe('My awesome test with declared types!', () => {
interface TestType {
value: number;
expected: number;
}
using<TestType>([{ value: 2, expected: 4 }], (data) => {
it('should calc with operator ^2', () => {
const result = calculator.calc(data.value, '^2');
expect(result).toEqual(data.expected);
});
});
using<TestType>({ desc: { value: 2, expected: 4 } }, (data, description) => {
it(description, () => {
const result = calculator.calc(data.value, '^2');
expect(result).toEqual(data.expected);
});
});
});