DefinitelyTyped/types/saywhen/index.d.ts
Chris Yungmann 6b2775d9b4 [jasmine] make SpyObjMethodNames more strongly-typed
When a generic type argument is provided, require the method names array
to only include keys of the generic type argument and for the object
syntax, additionally require that the setup returned type matches the
return type of the method. Requires TS 2.8 for conditional types.
2018-10-26 12:35:01 -05:00

39 lines
883 B
TypeScript

// Type definitions for saywhen 1.1
// Project: https://github.com/pushtechnology/saywhen
// Definitions by: Sean Sobey <https://github.com/SeanSobey>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
/// <reference types="jasmine" />
type Func = (...args: any[]) => any;
declare function when<T extends Func>(spy: T & jasmine.Spy): CallHandler<T>;
declare namespace when {
function captor<T>(val?: T): MatcherProxy<T>;
function noConflict(): void;
function is<T>(val: T): boolean;
}
interface CallHandler<T extends Func> {
readonly isCalled: Proxy<T>;
isCalledWith(...args: any[]): Proxy<T>;
}
interface Proxy<T extends Func> {
then(fn: T): Proxy<T>;
thenReturn(val: any): Proxy<T>;
thenThrow(err: Error): Proxy<T>;
}
interface MatcherProxy<T> {
(arg: T): boolean;
readonly latest: T;
values(): T[];
}
export = when;