From 4bdfa8fd6d27ed5a38d9aeb8714acc733fc2625c Mon Sep 17 00:00:00 2001 From: Lukas Zech Date: Tue, 14 Mar 2017 08:33:15 +0100 Subject: [PATCH] Add comments to tests for generic version of jasmine.objectContaining --- jasmine/index.d.ts | 2 +- jasmine/jasmine-tests.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/jasmine/index.d.ts b/jasmine/index.d.ts index cb19aa7cd8..f75a9f2127 100644 --- a/jasmine/index.d.ts +++ b/jasmine/index.d.ts @@ -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; declare function expect>(actual: ArrayLike): jasmine.ArrayLikeMatchers; declare function expect(actual: T): jasmine.Matchers; -declare function expect(spy: Function): jasmine.Matchers; declare function fail(e?: any): void; /** Action method that should be called when the async work is complete */ diff --git a/jasmine/jasmine-tests.ts b/jasmine/jasmine-tests.ts index e80060510b..1c9d5366e1 100644 --- a/jasmine/jasmine-tests.ts +++ b/jasmine/jasmine-tests.ts @@ -679,12 +679,19 @@ describe("jasmine.objectContaining", () => { }); it("matches objects with the expect key/value pairs", () => { - expect(foo).toEqual(jasmine.objectContaining({ - 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({ + bar: '', + // foo: 1, <-- this would cause an error as `foo` is not defined in fooType })); });