Add comments to tests for generic version of jasmine.objectContaining

This commit is contained in:
Lukas Zech
2017-03-14 08:33:15 +01:00
parent 035b1e61a2
commit 4bdfa8fd6d
2 changed files with 12 additions and 5 deletions
+1 -1
View File
@@ -24,9 +24,9 @@ declare function afterEach(action: (done: DoneFn) => void, timeout?: number): vo
declare function beforeAll(action: (done: DoneFn) => void, timeout?: number): void;
declare function afterAll(action: (done: DoneFn) => void, timeout?: number): void;
declare function expect(spy: Function): jasmine.Matchers<any>;
declare function expect<T extends ArrayLike<T>>(actual: ArrayLike<T>): jasmine.ArrayLikeMatchers<T>;
declare function expect<T>(actual: T): jasmine.Matchers<T>;
declare function expect(spy: Function): jasmine.Matchers<any>;
declare function fail(e?: any): void;
/** Action method that should be called when the async work is complete */
+11 -4
View File
@@ -679,12 +679,19 @@ describe("jasmine.objectContaining", () => {
});
it("matches objects with the expect key/value pairs", () => {
expect(foo).toEqual(jasmine.objectContaining<fooType>({
bar: ''
// not explictly providing the type on objectContaining only guards against
// missmatching types on know properties
expect(foo).not.toEqual(jasmine.objectContaining({
a: 37,
foo: 2, // <-- this does not cause an error as the compiler cannot infer the type completely
// b: '123', <-- this would cause an error as `b` defined as number in fooType
}));
expect(foo).not.toEqual(jasmine.objectContaining({
a: 37
// explictly providing the type on objectContaining makes the guard more precise
// as misspelled properties are detected as well
expect(foo).not.toEqual(jasmine.objectContaining<fooType>({
bar: '',
// foo: 1, <-- this would cause an error as `foo` is not defined in fooType
}));
});