mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 21:00:01 +08:00
Merge pull request #21308 from lukas-zech-software/jasmine/#21305
[jasmine] Fix return type of `arrayContaining()` and add method for 2.8
This commit is contained in:
17
types/jasmine/index.d.ts
vendored
17
types/jasmine/index.d.ts
vendored
@@ -1,4 +1,4 @@
|
||||
// Type definitions for Jasmine 2.6.0
|
||||
// Type definitions for Jasmine 2.8.0
|
||||
// Project: http://jasmine.github.io/
|
||||
// Definitions by: Boris Yankov <https://github.com/borisyankov>, Theodore Brown <https://github.com/theodorejb>, David Pärsson <https://github.com/davidparsson>, Gabe Moothart <https://github.com/gmoothart>, Lukas Zech <https://github.com/lukas-zech-software>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@@ -88,7 +88,7 @@ declare function expect<T>(actual: ArrayLike<T>): jasmine.ArrayLikeMatchers<T>;
|
||||
* Create an expectation for a spec.
|
||||
* @param actual Actual computed value to test expectations against.
|
||||
*/
|
||||
declare function expect<T>(actual: T): jasmine.Matchers<T>;
|
||||
declare function expect<T>(actual?: T): jasmine.Matchers<T>;
|
||||
|
||||
/**
|
||||
* Explicitly mark a spec as failed.
|
||||
@@ -134,7 +134,8 @@ declare namespace jasmine {
|
||||
|
||||
function anything(): Any;
|
||||
|
||||
function arrayContaining(sample: any[]): ArrayContaining;
|
||||
function arrayContaining<T>(sample: ArrayLike<T>): ArrayContaining<T>;
|
||||
function arrayWithExactContents<T>(sample: ArrayLike<T>): ArrayContaining<T>;
|
||||
function objectContaining<T>(sample: Partial<T>): ObjectContaining<T>;
|
||||
function createSpy(name: string, originalFn?: Function): Spy;
|
||||
|
||||
@@ -172,8 +173,8 @@ declare namespace jasmine {
|
||||
[n: number]: T;
|
||||
}
|
||||
|
||||
interface ArrayContaining {
|
||||
new (sample: any[]): any;
|
||||
interface ArrayContaining<T> {
|
||||
new (sample: ArrayLike<T>): ArrayLike<T>;
|
||||
|
||||
asymmetricMatch(other: any): boolean;
|
||||
jasmineToString(): string;
|
||||
@@ -440,14 +441,16 @@ declare namespace jasmine {
|
||||
toThrow(expected?: any): boolean;
|
||||
toThrowError(message?: string | RegExp): boolean;
|
||||
toThrowError(expected?: new (...args: any[]) => Error, message?: string | RegExp): boolean;
|
||||
nothing(): Any;
|
||||
|
||||
not: Matchers<T>;
|
||||
|
||||
Any: Any;
|
||||
}
|
||||
|
||||
interface ArrayLikeMatchers<T> extends Matchers<ArrayLike<T>> {
|
||||
toBe(expected: Expected<ArrayLike<T>>, expectationFailOutput?: any): boolean;
|
||||
toEqual(expected: Expected<ArrayLike<T>>, expectationFailOutput?: any): boolean;
|
||||
toBe(expected: Expected<ArrayLike<T>> | ArrayContaining<T>, expectationFailOutput?: any): boolean;
|
||||
toEqual(expected: Expected<ArrayLike<T>> | ArrayContaining<T>, expectationFailOutput?: any): boolean;
|
||||
toContain(expected: Expected<T>, expectationFailOutput?: any): boolean;
|
||||
not: ArrayLikeMatchers<T>;
|
||||
}
|
||||
|
||||
@@ -665,6 +665,12 @@ describe("Multiple spies, when created manually", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("jasmine.nothing", () => {
|
||||
it("matches any value", () => {
|
||||
expect().nothing();
|
||||
});
|
||||
});
|
||||
|
||||
describe("jasmine.any", () => {
|
||||
it("matches any value", () => {
|
||||
expect({}).toEqual(jasmine.any(Object));
|
||||
@@ -754,7 +760,7 @@ describe("jasmine.objectContaining", () => {
|
||||
});
|
||||
|
||||
describe("jasmine.arrayContaining", () => {
|
||||
var foo: any;
|
||||
var foo: Array<number>;
|
||||
|
||||
beforeEach(() => {
|
||||
foo = [1, 2, 3, 4];
|
||||
@@ -763,6 +769,9 @@ describe("jasmine.arrayContaining", () => {
|
||||
it("matches arrays with some of the values", () => {
|
||||
expect(foo).toEqual(jasmine.arrayContaining([3, 1]));
|
||||
expect(foo).not.toEqual(jasmine.arrayContaining([6]));
|
||||
|
||||
expect(foo).toBe(jasmine.arrayContaining([3, 1]));
|
||||
expect(foo).not.toBe(jasmine.arrayContaining([6]));
|
||||
});
|
||||
|
||||
describe("when used with a spy", () => {
|
||||
@@ -777,6 +786,33 @@ describe("jasmine.arrayContaining", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("jasmine.arrayWithExactContents", () => {
|
||||
var foo: Array<number>;
|
||||
|
||||
beforeEach(() => {
|
||||
foo = [1, 2, 3, 4];
|
||||
});
|
||||
|
||||
it("matches arrays with exactly the same values", () => {
|
||||
expect(foo).toEqual(jasmine.arrayWithExactContents([1, 2, 3, 4]));
|
||||
expect(foo).not.toEqual(jasmine.arrayWithExactContents([6]));
|
||||
|
||||
expect(foo).toBe(jasmine.arrayWithExactContents([1, 2, 3, 4]));
|
||||
expect(foo).not.toBe(jasmine.arrayWithExactContents([6]));
|
||||
});
|
||||
|
||||
describe("when used with a spy", () => {
|
||||
it("is useful when comparing arguments", () => {
|
||||
var callback = jasmine.createSpy('callback');
|
||||
|
||||
callback([1, 2, 3, 4]);
|
||||
|
||||
expect(callback).toHaveBeenCalledWith(jasmine.arrayWithExactContents([1, 2, 3, 4]));
|
||||
expect(callback).not.toHaveBeenCalledWith(jasmine.arrayWithExactContents([5, 2]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Manually ticking the Jasmine Clock", () => {
|
||||
var timerCallback: any;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user