From 7b6c1e33ed6515f3d723056d5bde498d0bdffa46 Mon Sep 17 00:00:00 2001 From: Thomas Puttkamer Date: Mon, 13 Nov 2017 18:48:47 +0100 Subject: [PATCH] added type definitions for mochaccino --- types/mochaccino/index.d.ts | 71 +++++++++++++++++++++++++ types/mochaccino/mochaccino-tests.ts | 77 ++++++++++++++++++++++++++++ types/mochaccino/tsconfig.json | 22 ++++++++ types/mochaccino/tslint.json | 1 + 4 files changed, 171 insertions(+) create mode 100644 types/mochaccino/index.d.ts create mode 100644 types/mochaccino/mochaccino-tests.ts create mode 100644 types/mochaccino/tsconfig.json create mode 100644 types/mochaccino/tslint.json diff --git a/types/mochaccino/index.d.ts b/types/mochaccino/index.d.ts new file mode 100644 index 0000000000..9e40c8ef8a --- /dev/null +++ b/types/mochaccino/index.d.ts @@ -0,0 +1,71 @@ +// Type definitions for mochaccino 1.2 +// Project: https://github.com/pawelgalazka/mochaccino#readme +// Definitions by: Thomas-P +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + + +declare module 'mochaccino' { + + import * as Sinon from "sinon"; + + interface Expect { + not: Expect; + + toBe(arg: T): void; + + toContain(arg: T): void; + + toEqual(arg: T): void; + + toHaveBeenCalled(): void; + + toHaveBeenCalledWith(...arg: any[]): void; + + toHaveBeenCalledTimes(callCount: number): void; + + toBeDefined(): void; + + toBeUndefined(): void; + + toBeNull(): void; + + toBeTruthy(): void; + + toBeFalsy(): void; + + toBeLessThan(other: number): void; + + toBeGreaterThan(other: number): void; + + toThrow(): void; + + toThrowError(errType: T): void; + + toMatch(matchExpression: T): void; + } + + + interface SpyProxy { + and: SpyProxy; + spyProxy: true; + getSubject: () => Sinon.SinonStub; + callThrough: () => void; + returnValue: (obj: any) => void; + callFake: (fake: Function) => void; + } + + interface Dom { + exposedProperties: ['window', 'navigator', 'document']; + create: () => void; + destroy: () => void; + clear: () => void; + } + + export function expect(value: T): Expect; + + export function spy(...config: any[]): (...args: any[]) => SpyProxy; + + export const dom: Dom; +} diff --git a/types/mochaccino/mochaccino-tests.ts b/types/mochaccino/mochaccino-tests.ts new file mode 100644 index 0000000000..0ff4aa6023 --- /dev/null +++ b/types/mochaccino/mochaccino-tests.ts @@ -0,0 +1,77 @@ +import {dom, expect, spy} from 'mochaccino'; + + +/** + * spy test + * + */ +const obj = { + funcName: () => { + } +}; + +let s = spy(); +s(1, 2); +expect(s).toHaveBeenCalledWith(1, 2); +spy(obj, 'funcName'); +obj.funcName(); +expect(obj.funcName).toHaveBeenCalled(); +/***********************/ +s = spy(); +s(); +expect(s).toHaveBeenCalled(); +/***********************/ +s(obj, 'funcName').and.callFake(() => { + return 123; +}); +expect(obj.funcName()).toEqual(123); +spy(obj, 'funcName'); + +expect(obj.funcName).toHaveBeenCalled(); +/***********************/ +s(obj, 'funcName').and.callThrough(); +/***********************/ +s(obj, 'funcName').and.returnValue(5); +/***********************/ + + +/** + * dom test + */ +dom.create(); +dom.destroy(); +dom.clear(); + + +/** + * expect test + * + */ + +const a: number = 1; +const b: boolean = true; +const c: number = 2; +const f = () => { +}; +const ErrorType = new Error(); +const regexp = /123/; + +expect(true).toBeTruthy(); +expect(a).toBe(b); +expect(a).toEqual(b); +expect(a).toBeTruthy(); +expect(a).toBeFalsy(); +expect(a).toBeDefined(); +expect(a).toBeUndefined(); +expect(a).toBeNull(); +expect(a).toBeLessThan(c); +expect(a).toBeGreaterThan(c); +expect([1, 2]).toContain(1); +expect(f).toThrow(); +expect(f).toThrowError(ErrorType); +expect(s).toMatch(regexp); + + +expect(s).toHaveBeenCalled(); +expect(s).toHaveBeenCalledWith(1, '23'); +expect(s).toHaveBeenCalledTimes(55); diff --git a/types/mochaccino/tsconfig.json b/types/mochaccino/tsconfig.json new file mode 100644 index 0000000000..78893fab7d --- /dev/null +++ b/types/mochaccino/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": ["sinon"], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mochaccino-tests.ts" + ] +} diff --git a/types/mochaccino/tslint.json b/types/mochaccino/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/mochaccino/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }