Mark optional properties from ArrayContaining and ObjectContaining (#37053)

This commit is contained in:
Moshe Kolodny
2019-07-22 15:41:09 -04:00
committed by Wesley Wigham
parent 9f2a383644
commit 92bbfdf700
4 changed files with 54 additions and 8 deletions

View File

@@ -236,17 +236,17 @@ declare namespace jasmine {
}
interface ArrayContaining<T> {
new (sample: ArrayLike<T>): ArrayLike<T>;
new?(sample: ArrayLike<T>): ArrayLike<T>;
asymmetricMatch(other: any): boolean;
jasmineToString(): string;
jasmineToString?(): string;
}
interface ObjectContaining<T> {
new (sample: Partial<T>): Partial<T>;
new?(sample: Partial<T>): Partial<T>;
jasmineMatches(other: any, mismatchKeys: any[], mismatchValues: any[]): boolean;
jasmineToString(): string;
jasmineToString?(): string;
}
interface Block {

View File

@@ -837,6 +837,29 @@ describe("jasmine.any", () => {
});
});
describe('custom asymmetry', function() {
const tester = {
asymmetricMatch: (actual: string) => {
const secondValue = actual.split(',')[1];
return secondValue === 'bar';
},
};
it('dives in deep', function() {
expect('foo,bar,baz,quux').toEqual(tester);
});
describe('when used with a spy', function() {
it('is useful for comparing arguments', function() {
const callback = jasmine.createSpy('callback');
callback('foo,bar,baz');
expect(callback).toHaveBeenCalledWith(tester);
});
});
});
describe("jasmine.objectContaining", () => {
interface fooType {
a: number;

View File

@@ -245,17 +245,17 @@ declare namespace jasmine {
}
interface ArrayContaining<T> {
new (sample: ArrayLike<T>): ArrayLike<T>;
new?(sample: ArrayLike<T>): ArrayLike<T>;
asymmetricMatch(other: any): boolean;
jasmineToString(): string;
jasmineToString?(): string;
}
interface ObjectContaining<T> {
new (sample: Partial<T>): Partial<T>;
new?(sample: Partial<T>): Partial<T>;
jasmineMatches(other: any, mismatchKeys: any[], mismatchValues: any[]): boolean;
jasmineToString(): string;
jasmineToString?(): string;
}
interface Block {

View File

@@ -839,6 +839,29 @@ describe("jasmine.any", () => {
});
});
describe('custom asymmetry', function() {
const tester = {
asymmetricMatch: (actual: string) => {
const secondValue = actual.split(',')[1];
return secondValue === 'bar';
},
};
it('dives in deep', function() {
expect('foo,bar,baz,quux').toEqual(tester);
});
describe('when used with a spy', function() {
it('is useful for comparing arguments', function() {
const callback = jasmine.createSpy('callback');
callback('foo,bar,baz');
expect(callback).toHaveBeenCalledWith(tester);
});
});
});
describe("jasmine.objectContaining", () => {
interface fooType {
a: number;