From 09a6331c194ea5c80de7f6d5f1d7a74cddeaa0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 16 Oct 2018 20:01:36 +0200 Subject: [PATCH] [jasmine-data-provider] adding a new definition (#29772) * init * strict fix * fix strict-export-declare-modifiers * change required ts version * Revert "change required ts version" This reverts commit 6ec355299606fb5b19b45126d8d4c0090f139ab0. * apply requested changes --- types/jasmine-data-provider/index.d.ts | 14 ++++++ .../jasmine-data-provider-tests.ts | 48 +++++++++++++++++++ types/jasmine-data-provider/tsconfig.json | 23 +++++++++ types/jasmine-data-provider/tslint.json | 3 ++ 4 files changed, 88 insertions(+) create mode 100644 types/jasmine-data-provider/index.d.ts create mode 100644 types/jasmine-data-provider/jasmine-data-provider-tests.ts create mode 100644 types/jasmine-data-provider/tsconfig.json create mode 100644 types/jasmine-data-provider/tslint.json diff --git a/types/jasmine-data-provider/index.d.ts b/types/jasmine-data-provider/index.d.ts new file mode 100644 index 0000000000..65ae1af270 --- /dev/null +++ b/types/jasmine-data-provider/index.d.ts @@ -0,0 +1,14 @@ +// Type definitions for jasmine-data-provider 2.2 +// Project: https://github.com/MortalFlesh/jasmine-data-provider +// Definitions by: Tomek Łaziuk +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +declare function using(values: using.ValueType, func: (data: T) => void): void; +declare function using(values: using.ValueType, func: (data: T[K], description: K) => void): void; + +declare namespace using { + type ValueType = T | (() => T); +} + +export = using; diff --git a/types/jasmine-data-provider/jasmine-data-provider-tests.ts b/types/jasmine-data-provider/jasmine-data-provider-tests.ts new file mode 100644 index 0000000000..bccc74f863 --- /dev/null +++ b/types/jasmine-data-provider/jasmine-data-provider-tests.ts @@ -0,0 +1,48 @@ +import * as using from 'jasmine-data-provider'; +import 'jasmine'; + +declare const calculator: any; + +describe('test subtraction with data provider - direct array', () => { + using([{ a: 5, b: 2, expected: 3 }, { a: 25, b: 26, expected: -1 }], (data) => { + it('should calc with operator -', () => { + const result = calculator.calc(data.a, data.b, '-'); + + expect(result).toEqual(data.expected); + }); + }); +}); + +describe('test addition with data provider - provider function', () => { + function plusProvider() { + return [ + { a: 2, b: 3, expected: 5 }, + { a: '14', b: 15, expected: 29 }, + { a: 12, b: '13', expected: 25 }, + { a: '22', b: '13', expected: 35 }, + ]; + } + + using(plusProvider, (data) => { + it('should calc with operator +', () => { + const result = calculator.calc(data.a, data.b, '+'); + + expect(result).toEqual(data.expected); + }); + }); +}); + +describe('My fantastic test', () => { + const objectDataProvider = { + 'First one is awesome!': { a: 6, b: 3, expected: 9 }, + 'Second test should fail': { a: 8, b: 1, expected: 10 } + }; + + using(objectDataProvider, (data, description) => { + it(description, () => { + const result = calculator.calc(data.a, data.b, '+'); + + expect(result).toEqual(data.expected); + }); + }); +}); diff --git a/types/jasmine-data-provider/tsconfig.json b/types/jasmine-data-provider/tsconfig.json new file mode 100644 index 0000000000..4ad53680f8 --- /dev/null +++ b/types/jasmine-data-provider/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "jasmine-data-provider-tests.ts" + ] +} diff --git a/types/jasmine-data-provider/tslint.json b/types/jasmine-data-provider/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/jasmine-data-provider/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}