added type definitions for mochaccino

This commit is contained in:
Thomas Puttkamer 2017-11-13 18:48:47 +01:00
parent 642e90f456
commit 7b6c1e33ed
4 changed files with 171 additions and 0 deletions

71
types/mochaccino/index.d.ts vendored Normal file
View File

@ -0,0 +1,71 @@
// Type definitions for mochaccino 1.2
// Project: https://github.com/pawelgalazka/mochaccino#readme
// Definitions by: Thomas-P <https://github.com/thomas-p>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../sinon/index.d.ts" />
declare module 'mochaccino' {
import * as Sinon from "sinon";
interface Expect {
not: Expect;
toBe<T>(arg: T): void;
toContain<T>(arg: T): void;
toEqual<T>(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<T>(errType: T): void;
toMatch<T>(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<T>(value: T): Expect;
export function spy(...config: any[]): (...args: any[]) => SpyProxy;
export const dom: Dom;
}

View File

@ -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);

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }