Merge pull request #30009 from CarsonF/bugfix/jest-extend

[Jest] - Fix returning message as string for custom matchers
This commit is contained in:
Ron Buckton
2018-10-27 14:45:17 -07:00
committed by GitHub
2 changed files with 24 additions and 1 deletions
+8 -1
View File
@@ -345,7 +345,14 @@ declare namespace jest {
}
interface ExpectExtendMap {
[key: string]: (this: MatcherUtils, received: any, ...actual: any[]) => { message(): string | (() => string), pass: boolean } | Promise<{ message(): string, pass: boolean }>;
[key: string]: CustomMatcher;
}
type CustomMatcher = (this: MatcherUtils, received: any, ...actual: any[]) => CustomMatcherResult | Promise<CustomMatcherResult>;
interface CustomMatcherResult {
pass: boolean;
message: string | (() => string);
}
interface SnapshotSerializerOptions {
+16
View File
@@ -433,6 +433,14 @@ expect.extend({
};
}
});
expect.extend({
foo(this: jest.MatcherUtils, received: {}, ...actual: Array<{}>) {
return {
message: JSON.stringify(received),
pass: false,
};
}
});
expect.extend({
async foo(this: jest.MatcherUtils, received: {}, ...actual: Array<{}>) {
return {
@@ -441,6 +449,14 @@ expect.extend({
};
}
});
expect.extend({
async foo(this: jest.MatcherUtils, received: {}, ...actual: Array<{}>) {
return {
message: JSON.stringify(received),
pass: false
};
}
});
expect.extend({
foo(this: jest.MatcherUtils) {
const isNot: boolean = this.isNot;