mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
[jasmine] Support Jasmine 3.5 (#40568)
* [jasmine] Add EnvConfiguration.failSpecWithNoExpectations property * [jasmine] Add jasmine.addAsyncMatchers * [jasmine] Add jasmine.setDefaultSpyStrategy * [jasmine] Add propertyNames parameter to jasmine.createSpyObj * [jasmine] Add jasmine.toBeInstanceOf matcher * [jasmine] Add jasmine.toBeTrue and jasmine.toBeFalse matchers * [jasmine] Update ts 3.1 types * [jasmine] fix linting issues * [jasmine] add EnvConfiguration.promise function * [jasmine] format tests and remove obsolete test * [jasmine] add toBeRejectedWithError AsyncMatcher * [jasmine] fix toBeRejectedWithError type * [jasmine] fix function formatting * [jasmine] fix test name
This commit is contained in:
committed by
Sheetal Nandi
parent
c5687bab45
commit
c0e76f846e
Vendored
+31
-7
@@ -1,4 +1,4 @@
|
||||
// Type definitions for Jasmine 3.4
|
||||
// Type definitions for Jasmine 3.5
|
||||
// Project: http://jasmine.github.io
|
||||
// Definitions by: Boris Yankov <https://github.com/borisyankov>
|
||||
// Theodore Brown <https://github.com/theodorejb>
|
||||
@@ -204,6 +204,11 @@ declare namespace jasmine {
|
||||
(ReadonlyArray<string> | { [methodName: string]: any }) :
|
||||
(ReadonlyArray<keyof T> | { [P in keyof T]?: T[P] extends Func ? ReturnType<T[P]> : any });
|
||||
|
||||
type SpyObjPropertyNames<T = undefined> =
|
||||
T extends undefined ?
|
||||
(ReadonlyArray<string> | { [propertyName: string]: any }) :
|
||||
(ReadonlyArray<keyof T>);
|
||||
|
||||
/**
|
||||
* Configuration that can be used when configuring Jasmine via {@link jasmine.Env.configure}
|
||||
*/
|
||||
@@ -211,9 +216,11 @@ declare namespace jasmine {
|
||||
random?: boolean;
|
||||
seed?: number;
|
||||
failFast?: boolean;
|
||||
failSpecWithNoExpectations?: boolean;
|
||||
oneFailurePerSpec?: boolean;
|
||||
hideDisabled?: boolean;
|
||||
specFilter?: Function;
|
||||
promise?: Function;
|
||||
}
|
||||
|
||||
function clock(): Clock;
|
||||
@@ -257,13 +264,13 @@ declare namespace jasmine {
|
||||
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 setDefaultSpyStrategy(and: SpyAnd): void;
|
||||
function createSpy(name?: string, originalFn?: Function): Spy;
|
||||
|
||||
function createSpyObj(baseName: string, methodNames: SpyObjMethodNames): any;
|
||||
function createSpyObj<T>(baseName: string, methodNames: SpyObjMethodNames<T>): SpyObj<T>;
|
||||
|
||||
function createSpyObj(methodNames: SpyObjMethodNames): any;
|
||||
function createSpyObj<T>(methodNames: SpyObjMethodNames<T>): SpyObj<T>;
|
||||
function createSpyObj(baseName: string, methodNames: SpyObjMethodNames, propertyNames?: SpyObjPropertyNames): any;
|
||||
function createSpyObj<T>(baseName: string, methodNames: SpyObjMethodNames<T>, propertyNames?: SpyObjPropertyNames<T>): SpyObj<T>;
|
||||
function createSpyObj(methodNames: SpyObjMethodNames, propertyNames?: SpyObjPropertyNames): any;
|
||||
function createSpyObj<T>(methodNames: SpyObjMethodNames<T>, propertyNames?: SpyObjPropertyNames<T>): SpyObj<T>;
|
||||
|
||||
function pp(value: any): string;
|
||||
|
||||
@@ -272,6 +279,7 @@ declare namespace jasmine {
|
||||
function addCustomEqualityTester(equalityTester: CustomEqualityTester): void;
|
||||
|
||||
function addMatchers(matchers: CustomMatcherFactories): void;
|
||||
function addAsyncMatchers(matchers: CustomMatcherFactories): void;
|
||||
|
||||
function stringMatching(str: string | RegExp): AsymmetricMatcher<string>;
|
||||
|
||||
@@ -564,6 +572,8 @@ declare namespace jasmine {
|
||||
toBeNaN(): boolean;
|
||||
toBeTruthy(expectationFailOutput?: any): boolean;
|
||||
toBeFalsy(expectationFailOutput?: any): boolean;
|
||||
toBeTrue(): boolean;
|
||||
toBeFalse(): boolean;
|
||||
toHaveBeenCalled(): boolean;
|
||||
toHaveBeenCalledBefore(expected: Spy): boolean;
|
||||
toHaveBeenCalledWith(...params: any[]): boolean;
|
||||
@@ -580,6 +590,7 @@ declare namespace jasmine {
|
||||
toThrowMatching(predicate: (thrown: any) => boolean): boolean;
|
||||
toBeNegativeInfinity(expectationFailOutput?: any): boolean;
|
||||
toBePositiveInfinity(expectationFailOutput?: any): boolean;
|
||||
toBeInstanceOf(expected: Constructor): boolean;
|
||||
|
||||
/**
|
||||
* Expect the actual value to be a DOM element that has the expected class.
|
||||
@@ -667,6 +678,19 @@ declare namespace jasmine {
|
||||
*/
|
||||
toBeRejectedWith(expected: Expected<U>): PromiseLike<void>;
|
||||
|
||||
/**
|
||||
* Expect a promise to be rejected with a value matched to the expected.
|
||||
* @param expected - Error constructor the object that was thrown needs to be an instance of. If not provided, Error will be used.
|
||||
* @param message - The message that should be set on the thrown Error.
|
||||
*/
|
||||
toBeRejectedWithError(expected?: new (...args: any[]) => Error, message?: string | RegExp): PromiseLike<void>;
|
||||
|
||||
/**
|
||||
* Expect a promise to be rejected with a value matched to the expected.
|
||||
* @param message - The message that should be set on the thrown Error.
|
||||
*/
|
||||
toBeRejectedWithError(message?: string | RegExp): PromiseLike<void>;
|
||||
|
||||
/**
|
||||
* Add some context for an expect.
|
||||
* @param message - Additional context to show when the matcher fails.
|
||||
|
||||
@@ -59,7 +59,7 @@ describe("Included matchers:", () => {
|
||||
});
|
||||
|
||||
it("should work for optional values", () => {
|
||||
const opt: string | undefined = Math.random() > .5 ? "s" : undefined;
|
||||
const opt: string | undefined = Math.random() > .5 ? "s" : undefined;
|
||||
expect(opt).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
@@ -115,6 +115,18 @@ describe("Included matchers:", () => {
|
||||
expect(foo).not.toBeFalsy();
|
||||
});
|
||||
|
||||
it("The 'toBeTrue' matcher is for matching with true", () => {
|
||||
expect(true).toBeTrue();
|
||||
expect(false).not.toBeTrue();
|
||||
expect({}).not.toBeTrue();
|
||||
});
|
||||
|
||||
it("The 'toBeFalse' matcher is for matching with false", () => {
|
||||
expect(false).toBeFalse();
|
||||
expect(true).not.toBeFalse();
|
||||
expect(undefined).not.toBeFalse();
|
||||
});
|
||||
|
||||
it("The 'toContain' matcher is for finding an item in an Array", () => {
|
||||
const a = ["foo", "bar", "baz"];
|
||||
|
||||
@@ -179,6 +191,15 @@ describe("Included matchers:", () => {
|
||||
expect(foo).toThrowError(TypeError, "foo bar baz");
|
||||
});
|
||||
|
||||
it("The 'toBeInstanceOf' matcher is for testing if the actual is of the expected class", () => {
|
||||
class MyClass { }
|
||||
|
||||
expect(new MyClass()).toBeInstanceOf(MyClass);
|
||||
expect('foo').toBeInstanceOf(String);
|
||||
expect(3).toBeInstanceOf(Number);
|
||||
expect(new Error()).toBeInstanceOf(Error);
|
||||
});
|
||||
|
||||
it("async matchers", async () => {
|
||||
const badness = new Error("badness");
|
||||
await expectAsync(Promise.resolve()).toBeResolved();
|
||||
@@ -187,6 +208,11 @@ describe("Included matchers:", () => {
|
||||
await expectAsync(Promise.reject(badness)).toBeRejected();
|
||||
await expectAsync(Promise.reject(badness)).toBeRejected("bad mojo");
|
||||
await expectAsync(Promise.reject(badness)).toBeRejectedWith(badness);
|
||||
await expectAsync(Promise.reject(badness)).toBeRejectedWithError(Error, "badness");
|
||||
await expectAsync(Promise.reject(badness)).toBeRejectedWithError(Error, /badness/);
|
||||
await expectAsync(Promise.reject(badness)).toBeRejectedWithError(Error);
|
||||
await expectAsync(Promise.reject(badness)).toBeRejectedWithError("badness");
|
||||
await expectAsync(Promise.reject(badness)).toBeRejectedWithError(/badness/);
|
||||
await expectAsync(Promise.resolve()).withContext("additional info").toBeResolved();
|
||||
});
|
||||
|
||||
@@ -197,6 +223,10 @@ describe("Included matchers:", () => {
|
||||
await expectAsync(Promise.resolve(true)).not.toBeResolvedTo(false);
|
||||
await expectAsync(Promise.resolve()).not.toBeRejected();
|
||||
await expectAsync(Promise.reject(badness)).not.toBeRejectedWith(malady);
|
||||
await expectAsync(Promise.reject(badness)).not.toBeRejectedWithError(Error, "malady");
|
||||
await expectAsync(Promise.reject(badness)).not.toBeRejectedWithError(Error, /malady/);
|
||||
await expectAsync(Promise.reject(badness)).not.toBeRejectedWithError("malady");
|
||||
await expectAsync(Promise.reject(badness)).not.toBeRejectedWithError(/malady/);
|
||||
await expectAsync(Promise.reject(badness)).not.withContext("additional info").toBeResolved();
|
||||
await expectAsync(Promise.reject(badness)).withContext("additional info").not.toBeResolved();
|
||||
});
|
||||
@@ -991,7 +1021,7 @@ describe("jasmine.objectContaining", () => {
|
||||
};
|
||||
|
||||
expect(nestedFoo).toEqual({
|
||||
nested: jasmine.objectContaining({b: 2})
|
||||
nested: jasmine.objectContaining({ b: 2 })
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1326,25 +1356,25 @@ describe('better typed spys', () => {
|
||||
const spy = spyOn(foo, 'method');
|
||||
const spy2 = spyOn(foo, 'value'); // Is an error with TS 3.1+ typings.
|
||||
|
||||
// $ExpectType any
|
||||
// $ExpectType any
|
||||
spy.calls.first().returnValue;
|
||||
});
|
||||
it('works on constructors', () => {
|
||||
class MyClass {
|
||||
constructor(readonly foo: string) {}
|
||||
constructor(readonly foo: string) { }
|
||||
}
|
||||
const namespace = { MyClass };
|
||||
const spy = spyOn(namespace, 'MyClass');
|
||||
spy.and.returnValue({foo: 'test'});
|
||||
spy.and.returnValue({ foo: 'test' });
|
||||
spy.and.returnValue({}); // Is an error with TS 3.1+ typings.
|
||||
spy.and.returnValue({foo: 123}); // Is an error with TS 3.1+ typings.
|
||||
spy.and.returnValue({ foo: 123 }); // Is an error with TS 3.1+ typings.
|
||||
});
|
||||
it('can allows overriding the generic', () => {
|
||||
class Base {
|
||||
service() {}
|
||||
service() { }
|
||||
}
|
||||
class Super extends Base {
|
||||
service2() {}
|
||||
service2() { }
|
||||
}
|
||||
spyOn<Base>(new Super(), 'service');
|
||||
spyOn<Base>(new Super(), 'service2'); // $ExpectError
|
||||
@@ -1433,7 +1463,7 @@ describe("Randomize Tests", () => {
|
||||
// Dest spces copied from jasmine project (https://github.com/jasmine/jasmine/blob/master/spec/core/SpecSpec.js)
|
||||
describe("createSpyObj", function() {
|
||||
it("should create an object with spy methods and corresponding return values when you call jasmine.createSpyObj() with an object", function() {
|
||||
const spyObj = jasmine.createSpyObj('BaseName', {method1: 42, method2: 'special sauce'});
|
||||
const spyObj = jasmine.createSpyObj('BaseName', { method1: 42, method2: 'special sauce' });
|
||||
|
||||
expect(spyObj.method1()).toEqual(42);
|
||||
expect(spyObj.method1.and.identity()).toEqual('BaseName.method1');
|
||||
@@ -1451,7 +1481,7 @@ describe("createSpyObj", function() {
|
||||
});
|
||||
|
||||
it("should allow you to omit the baseName and takes only an object", function() {
|
||||
const spyObj = jasmine.createSpyObj({method1: 42, method2: 'special sauce'});
|
||||
const spyObj = jasmine.createSpyObj({ method1: 42, method2: 'special sauce' });
|
||||
|
||||
expect(spyObj.method1()).toEqual(42);
|
||||
expect(spyObj.method1.and.identity()).toEqual('unknown.method1');
|
||||
@@ -1479,47 +1509,70 @@ describe("createSpyObj", function() {
|
||||
jasmine.createSpyObj('BaseName', {});
|
||||
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
|
||||
});
|
||||
|
||||
it("creates an object with property names and return values if second object is passed", function() {
|
||||
const spyObj = jasmine.createSpyObj('base', ['method1'], {
|
||||
prop1: 'foo',
|
||||
prop2: 37
|
||||
});
|
||||
|
||||
expect(spyObj).toEqual({
|
||||
method1: jasmine.any(Function)
|
||||
});
|
||||
|
||||
expect(spyObj.prop1).toEqual('foo');
|
||||
expect(spyObj.prop2).toEqual(37);
|
||||
spyObj.prop2 = 4;
|
||||
expect(spyObj.prop2).toEqual(37);
|
||||
});
|
||||
|
||||
it("allows base name to be ommitted when assigning methods and properties", function() {
|
||||
const spyObj = jasmine.createSpyObj({ m: 3 }, { p: 4 });
|
||||
|
||||
expect(spyObj.m()).toEqual(3);
|
||||
expect(spyObj.p).toEqual(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Static Matcher Test', function() {
|
||||
it('Falsy', () => {
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.falsy(),
|
||||
})
|
||||
);
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.falsy(),
|
||||
})
|
||||
);
|
||||
});
|
||||
it('Truthy', () => {
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.truthy(),
|
||||
})
|
||||
);
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.truthy(),
|
||||
})
|
||||
);
|
||||
});
|
||||
it('Empty', () => {
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.empty(),
|
||||
})
|
||||
);
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.empty(),
|
||||
})
|
||||
);
|
||||
});
|
||||
it('NotEmpty', () => {
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.notEmpty(),
|
||||
})
|
||||
);
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.notEmpty(),
|
||||
})
|
||||
);
|
||||
});
|
||||
it('Partial should OK', () => {
|
||||
expect({ value: null, label: 'abcd' }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.anything(),
|
||||
})
|
||||
);
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: 'any value should ok',
|
||||
})
|
||||
expect({ value: null, label: 'abcd' }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.anything(),
|
||||
})
|
||||
);
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: 'any value should ok',
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Vendored
+30
-6
@@ -207,6 +207,11 @@ declare namespace jasmine {
|
||||
(ReadonlyArray<string> | { [methodName: string]: any }) :
|
||||
(ReadonlyArray<keyof T> | { [P in keyof T]?: T[P] extends Func ? ReturnType<T[P]> : any });
|
||||
|
||||
type SpyObjPropertyNames<T = undefined> =
|
||||
T extends undefined ?
|
||||
(ReadonlyArray<string> | { [propertyName: string]: any }) :
|
||||
(ReadonlyArray<keyof T>);
|
||||
|
||||
/**
|
||||
* Configuration that can be used when configuring Jasmine via {@link jasmine.Env.configure}
|
||||
*/
|
||||
@@ -214,9 +219,11 @@ declare namespace jasmine {
|
||||
random?: boolean;
|
||||
seed?: number;
|
||||
failFast?: boolean;
|
||||
failSpecWithNoExpectations?: boolean;
|
||||
oneFailurePerSpec?: boolean;
|
||||
hideDisabled?: boolean;
|
||||
specFilter?: Function;
|
||||
promise?: Function;
|
||||
}
|
||||
|
||||
function clock(): Clock;
|
||||
@@ -260,13 +267,13 @@ declare namespace jasmine {
|
||||
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 setDefaultSpyStrategy<Fn extends Func = Func>(and: SpyAnd<Fn>): void;
|
||||
function createSpy<Fn extends Func>(name?: string, originalFn?: Fn): Spy<Fn>;
|
||||
|
||||
function createSpyObj(baseName: string, methodNames: SpyObjMethodNames): any;
|
||||
function createSpyObj<T>(baseName: string, methodNames: SpyObjMethodNames<T>): SpyObj<T>;
|
||||
|
||||
function createSpyObj(methodNames: SpyObjMethodNames): any;
|
||||
function createSpyObj<T>(methodNames: SpyObjMethodNames<T>): SpyObj<T>;
|
||||
function createSpyObj(baseName: string, methodNames: SpyObjMethodNames, propertyNames?: SpyObjPropertyNames): any;
|
||||
function createSpyObj<T>(baseName: string, methodNames: SpyObjMethodNames<T>, propertyNames?: SpyObjPropertyNames<T>): SpyObj<T>;
|
||||
function createSpyObj(methodNames: SpyObjMethodNames, propertyNames?: SpyObjPropertyNames): any;
|
||||
function createSpyObj<T>(methodNames: SpyObjMethodNames<T>, propertyNames?: SpyObjPropertyNames<T>): SpyObj<T>;
|
||||
|
||||
function pp(value: any): string;
|
||||
|
||||
@@ -275,6 +282,7 @@ declare namespace jasmine {
|
||||
function addCustomEqualityTester(equalityTester: CustomEqualityTester): void;
|
||||
|
||||
function addMatchers(matchers: CustomMatcherFactories): void;
|
||||
function addAsyncMatchers(matchers: CustomMatcherFactories): void;
|
||||
|
||||
function stringMatching(str: string | RegExp): AsymmetricMatcher<string>;
|
||||
|
||||
@@ -567,6 +575,8 @@ declare namespace jasmine {
|
||||
toBeNaN(): boolean;
|
||||
toBeTruthy(expectationFailOutput?: any): boolean;
|
||||
toBeFalsy(expectationFailOutput?: any): boolean;
|
||||
toBeTrue(): boolean;
|
||||
toBeFalse(): boolean;
|
||||
toHaveBeenCalled(): boolean;
|
||||
toHaveBeenCalledBefore(expected: Func): boolean;
|
||||
toHaveBeenCalledWith(...params: any[]): boolean;
|
||||
@@ -583,6 +593,7 @@ declare namespace jasmine {
|
||||
toThrowMatching(predicate: (thrown: any) => boolean): boolean;
|
||||
toBeNegativeInfinity(expectationFailOutput?: any): boolean;
|
||||
toBePositiveInfinity(expectationFailOutput?: any): boolean;
|
||||
toBeInstanceOf(expected: Constructor): boolean;
|
||||
|
||||
/**
|
||||
* Expect the actual value to be a DOM element that has the expected class.
|
||||
@@ -687,6 +698,19 @@ declare namespace jasmine {
|
||||
*/
|
||||
toBeRejectedWith(expected: Expected<U>): Promise<void>;
|
||||
|
||||
/**
|
||||
* Expect a promise to be rejected with a value matched to the expected.
|
||||
* @param expected - Error constructor the object that was thrown needs to be an instance of. If not provided, Error will be used.
|
||||
* @param message - The message that should be set on the thrown Error.
|
||||
*/
|
||||
toBeRejectedWithError(expected?: new (...args: any[]) => Error, message?: string | RegExp): Promise<void>;
|
||||
|
||||
/**
|
||||
* Expect a promise to be rejected with a value matched to the expected.
|
||||
* @param message - The message that should be set on the thrown Error.
|
||||
*/
|
||||
toBeRejectedWithError(message?: string | RegExp): Promise<void>;
|
||||
|
||||
/**
|
||||
* Add some context for an expect.
|
||||
* @param message - Additional context to show when the matcher fails.
|
||||
|
||||
@@ -59,7 +59,7 @@ describe("Included matchers:", () => {
|
||||
});
|
||||
|
||||
it("should work for optional values", () => {
|
||||
const opt: string | undefined = Math.random() > .5 ? "s" : undefined;
|
||||
const opt: string | undefined = Math.random() > .5 ? "s" : undefined;
|
||||
expect(opt).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
@@ -115,6 +115,18 @@ describe("Included matchers:", () => {
|
||||
expect(foo).not.toBeFalsy();
|
||||
});
|
||||
|
||||
it("The 'toBeTrue' matcher is for matching with true", () => {
|
||||
expect(true).toBeTrue();
|
||||
expect(false).not.toBeTrue();
|
||||
expect({}).not.toBeTrue();
|
||||
});
|
||||
|
||||
it("The 'toBeFalse' matcher is for matching with false", () => {
|
||||
expect(false).toBeFalse();
|
||||
expect(true).not.toBeFalse();
|
||||
expect(undefined).not.toBeFalse();
|
||||
});
|
||||
|
||||
it("The 'toContain' matcher is for finding an item in an Array", () => {
|
||||
const a = ["foo", "bar", "baz"];
|
||||
|
||||
@@ -179,6 +191,15 @@ describe("Included matchers:", () => {
|
||||
expect(foo).toThrowError(TypeError, "foo bar baz");
|
||||
});
|
||||
|
||||
it("The 'toBeInstanceOf' matcher is for testing if the actual is of the expected class", () => {
|
||||
class MyClass { }
|
||||
|
||||
expect(new MyClass()).toBeInstanceOf(MyClass);
|
||||
expect('foo').toBeInstanceOf(String);
|
||||
expect(3).toBeInstanceOf(Number);
|
||||
expect(new Error()).toBeInstanceOf(Error);
|
||||
});
|
||||
|
||||
it("async matchers", async () => {
|
||||
const badness = new Error("badness");
|
||||
await expectAsync(Promise.resolve()).toBeResolved();
|
||||
@@ -187,6 +208,11 @@ describe("Included matchers:", () => {
|
||||
await expectAsync(Promise.reject(badness)).toBeRejected();
|
||||
await expectAsync(Promise.reject(badness)).toBeRejected("bad mojo");
|
||||
await expectAsync(Promise.reject(badness)).toBeRejectedWith(badness);
|
||||
await expectAsync(Promise.reject(badness)).toBeRejectedWithError(Error, "badness");
|
||||
await expectAsync(Promise.reject(badness)).toBeRejectedWithError(Error, /badness/);
|
||||
await expectAsync(Promise.reject(badness)).toBeRejectedWithError(Error);
|
||||
await expectAsync(Promise.reject(badness)).toBeRejectedWithError("badness");
|
||||
await expectAsync(Promise.reject(badness)).toBeRejectedWithError(/badness/);
|
||||
await expectAsync(Promise.resolve()).withContext("additional info").toBeResolved();
|
||||
});
|
||||
|
||||
@@ -197,6 +223,10 @@ describe("Included matchers:", () => {
|
||||
await expectAsync(Promise.resolve(true)).not.toBeResolvedTo(false);
|
||||
await expectAsync(Promise.resolve()).not.toBeRejected();
|
||||
await expectAsync(Promise.reject(badness)).not.toBeRejectedWith(malady);
|
||||
await expectAsync(Promise.reject(badness)).not.toBeRejectedWithError(Error, "malady");
|
||||
await expectAsync(Promise.reject(badness)).not.toBeRejectedWithError(Error, /malady/);
|
||||
await expectAsync(Promise.reject(badness)).not.toBeRejectedWithError("malady");
|
||||
await expectAsync(Promise.reject(badness)).not.toBeRejectedWithError(/malady/);
|
||||
await expectAsync(Promise.reject(badness)).not.withContext("additional info").toBeResolved();
|
||||
await expectAsync(Promise.reject(badness)).withContext("additional info").not.toBeResolved();
|
||||
});
|
||||
@@ -991,7 +1021,7 @@ describe("jasmine.objectContaining", () => {
|
||||
};
|
||||
|
||||
expect(nestedFoo).toEqual({
|
||||
nested: jasmine.objectContaining({b: 2})
|
||||
nested: jasmine.objectContaining({ b: 2 })
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1326,25 +1356,25 @@ describe('better typed spys', () => {
|
||||
const spy = spyOn(foo, 'method');
|
||||
const spy2 = spyOn(foo, 'value'); // $ExpectError
|
||||
|
||||
// $ExpectType string
|
||||
// $ExpectType string
|
||||
spy.calls.first().returnValue;
|
||||
});
|
||||
it('works on constructors', () => {
|
||||
class MyClass {
|
||||
constructor(readonly foo: string) {}
|
||||
constructor(readonly foo: string) { }
|
||||
}
|
||||
const namespace = { MyClass };
|
||||
const spy = spyOn(namespace, 'MyClass');
|
||||
spy.and.returnValue({foo: 'test'});
|
||||
spy.and.returnValue({ foo: 'test' });
|
||||
spy.and.returnValue({}); // $ExpectError
|
||||
spy.and.returnValue({foo: 123}); // $ExpectError
|
||||
spy.and.returnValue({ foo: 123 }); // $ExpectError
|
||||
});
|
||||
it('can allows overriding the generic', () => {
|
||||
class Base {
|
||||
service() {}
|
||||
service() { }
|
||||
}
|
||||
class Super extends Base {
|
||||
service2() {}
|
||||
service2() { }
|
||||
}
|
||||
spyOn<Base>(new Super(), 'service');
|
||||
spyOn<Base>(new Super(), 'service2'); // $ExpectError
|
||||
@@ -1433,7 +1463,7 @@ describe("Randomize Tests", () => {
|
||||
// Dest spces copied from jasmine project (https://github.com/jasmine/jasmine/blob/master/spec/core/SpecSpec.js)
|
||||
describe("createSpyObj", function() {
|
||||
it("should create an object with spy methods and corresponding return values when you call jasmine.createSpyObj() with an object", function() {
|
||||
const spyObj = jasmine.createSpyObj('BaseName', {method1: 42, method2: 'special sauce'});
|
||||
const spyObj = jasmine.createSpyObj('BaseName', { method1: 42, method2: 'special sauce' });
|
||||
|
||||
expect(spyObj.method1()).toEqual(42);
|
||||
expect(spyObj.method1.and.identity()).toEqual('BaseName.method1');
|
||||
@@ -1451,7 +1481,7 @@ describe("createSpyObj", function() {
|
||||
});
|
||||
|
||||
it("should allow you to omit the baseName and takes only an object", function() {
|
||||
const spyObj = jasmine.createSpyObj({method1: 42, method2: 'special sauce'});
|
||||
const spyObj = jasmine.createSpyObj({ method1: 42, method2: 'special sauce' });
|
||||
|
||||
expect(spyObj.method1()).toEqual(42);
|
||||
expect(spyObj.method1.and.identity()).toEqual('unknown.method1');
|
||||
@@ -1479,47 +1509,70 @@ describe("createSpyObj", function() {
|
||||
jasmine.createSpyObj('BaseName', {});
|
||||
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
|
||||
});
|
||||
|
||||
it("creates an object with property names and return values if second object is passed", function() {
|
||||
const spyObj = jasmine.createSpyObj('base', ['method1'], {
|
||||
prop1: 'foo',
|
||||
prop2: 37
|
||||
});
|
||||
|
||||
expect(spyObj).toEqual({
|
||||
method1: jasmine.any(Function)
|
||||
});
|
||||
|
||||
expect(spyObj.prop1).toEqual('foo');
|
||||
expect(spyObj.prop2).toEqual(37);
|
||||
spyObj.prop2 = 4;
|
||||
expect(spyObj.prop2).toEqual(37);
|
||||
});
|
||||
|
||||
it("allows base name to be ommitted when assigning methods and properties", function() {
|
||||
const spyObj = jasmine.createSpyObj({ m: 3 }, { p: 4 });
|
||||
|
||||
expect(spyObj.m()).toEqual(3);
|
||||
expect(spyObj.p).toEqual(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Static Matcher Test', function() {
|
||||
it('Falsy', () => {
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.falsy(),
|
||||
})
|
||||
);
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.falsy(),
|
||||
})
|
||||
);
|
||||
});
|
||||
it('Truthy', () => {
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.truthy(),
|
||||
})
|
||||
);
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.truthy(),
|
||||
})
|
||||
);
|
||||
});
|
||||
it('Empty', () => {
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.empty(),
|
||||
})
|
||||
);
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.empty(),
|
||||
})
|
||||
);
|
||||
});
|
||||
it('NotEmpty', () => {
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.notEmpty(),
|
||||
})
|
||||
);
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.notEmpty(),
|
||||
})
|
||||
);
|
||||
});
|
||||
it('Partial should OK', () => {
|
||||
expect({ value: null, label: 'abcd' }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.anything(),
|
||||
})
|
||||
);
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: 'any value should ok',
|
||||
})
|
||||
expect({ value: null, label: 'abcd' }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: jasmine.anything(),
|
||||
})
|
||||
);
|
||||
expect({ value: null }).toEqual(
|
||||
jasmine.objectContaining({
|
||||
value: 'any value should ok',
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user