diff --git a/types/mochaccino/index.d.ts b/types/mochaccino/index.d.ts new file mode 100644 index 0000000000..b230218ee9 --- /dev/null +++ b/types/mochaccino/index.d.ts @@ -0,0 +1,42 @@ +// Type definitions for mochaccino 1.2 +// Project: https://github.com/pawelgalazka/mochaccino#readme +// Definitions by: Thomas-P +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 +import * as Sinon from "sinon"; +export interface Expect { + not: Expect; + toBe(arg: any): void; + toContain(arg: any): void; + toEqual(arg: any): 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: any): void; + toMatch(matchExpression: any): void; +} +export interface SpyProxy { + and: SpyProxy; + spyProxy: true; + getSubject: () => Sinon.SinonStub; + callThrough: () => void; + returnValue: (obj: any) => void; + callFake: (fake: (...args: any[]) => any) => void; +} +export interface Dom { + exposedProperties: ['window', 'navigator', 'document']; + create: () => void; + destroy: () => void; + clear: () => void; +} +export function expect(value: any): 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..c63634e64c --- /dev/null +++ b/types/mochaccino/mochaccino-tests.ts @@ -0,0 +1,66 @@ +import { dom, expect, spy } from 'mochaccino'; +/** + * spy test + * + */ +const obj = { + funcName: (): any => { + } +}; +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 = 1; +const b = true; +const c = 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..166b3f4203 --- /dev/null +++ b/types/mochaccino/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", + "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" }