fix types for jasmine: allow partial properties when using objects (#42363)

Source reference from Jasmine:
a6a9550d1e/src/core/SpyFactory.js (L38-L49)
This commit is contained in:
Philip Peitsch 2020-02-15 04:33:17 +11:00 committed by GitHub
parent d66b9a5834
commit edfa6cda4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 2 deletions

View File

@ -207,7 +207,7 @@ declare namespace jasmine {
type SpyObjPropertyNames<T = undefined> =
T extends undefined ?
(ReadonlyArray<string> | { [propertyName: string]: any }) :
(ReadonlyArray<keyof T>);
(ReadonlyArray<keyof T> | { [P in keyof T]?: T[P] });
/**
* Configuration that can be used when configuring Jasmine via {@link jasmine.Env.configure}

View File

@ -1563,6 +1563,36 @@ describe("createSpyObj", function() {
expect(spyObj.m()).toEqual(3);
expect(spyObj.p).toEqual(4);
});
it("allows methods and properties lists to omit entries from typed object", function() {
interface Template {
method1(): number;
method2(): void;
readonly property1: string;
property2: number;
}
const spyObj = jasmine.createSpyObj<Template>(["method1"], ["property1"]);
expect(spyObj).toEqual({
method1: jasmine.any(Function),
method2: undefined as any,
property1: undefined as any,
property2: undefined as any
});
});
it("allows methods and properties objects to omit entries from typed object", function() {
interface Template {
method1(): number;
method2(): void;
readonly property1: string;
property2: number;
}
const spyObj = jasmine.createSpyObj<Template>({method1: 3}, {property1: "4"});
expect(spyObj.method1()).toEqual(3);
expect(spyObj.property1).toEqual("4");
});
});
describe('Static Matcher Test', function() {

View File

@ -210,7 +210,7 @@ declare namespace jasmine {
type SpyObjPropertyNames<T = undefined> =
T extends undefined ?
(ReadonlyArray<string> | { [propertyName: string]: any }) :
(ReadonlyArray<keyof T>);
(ReadonlyArray<keyof T> | { [P in keyof T]?: T[P] });
/**
* Configuration that can be used when configuring Jasmine via {@link jasmine.Env.configure}

View File

@ -1532,6 +1532,36 @@ describe("createSpyObj", function() {
expect(spyObj.m()).toEqual(3);
expect(spyObj.p).toEqual(4);
});
it("allows methods and properties lists to omit entries from typed object", function() {
interface Template {
method1(): number;
method2(): void;
readonly property1: string;
property2: number;
}
const spyObj = jasmine.createSpyObj<Template>(["method1"], ["property1"]);
expect(spyObj).toEqual({
method1: jasmine.any(Function),
method2: undefined as any,
property1: undefined as any,
property2: undefined as any
});
});
it("allows methods and properties objects to omit entries from typed object", function() {
interface Template {
method1(): number;
method2(): void;
readonly property1: string;
property2: number;
}
const spyObj = jasmine.createSpyObj<Template>({method1: 3}, {property1: "4"});
expect(spyObj.method1()).toEqual(3);
expect(spyObj.property1).toEqual("4");
});
});
describe('Static Matcher Test', function() {