mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Merge pull request #26051 from cexbrayat/fix/jasmine-negative-compare
Jasmine: Adds negativeCompare to CustomMatcher
This commit is contained in:
Vendored
+2
@@ -221,6 +221,8 @@ declare namespace jasmine {
|
||||
interface CustomMatcher {
|
||||
compare<T>(actual: T, expected: T, ...args: any[]): CustomMatcherResult;
|
||||
compare(actual: any, ...expected: any[]): CustomMatcherResult;
|
||||
negativeCompare?<T>(actual: T, expected: T, ...args: any[]): CustomMatcherResult;
|
||||
negativeCompare?(actual: any, ...expected: any[]): CustomMatcherResult;
|
||||
}
|
||||
|
||||
type CustomMatcherFactory = (util: MatchersUtil, customEqualityTesters: CustomEqualityTester[]) => CustomMatcher;
|
||||
|
||||
@@ -968,7 +968,13 @@ var customMatchers: jasmine.CustomMatcherFactories = {
|
||||
return {
|
||||
compare: (actual: any, floor: number, ceiling: number): jasmine.CustomMatcherResult => {
|
||||
const pass = actual >= floor && actual <= ceiling;
|
||||
const message = `expected ${actual} ${pass ? 'not ' : ''} to be within range ${floor}-${ceiling}`;
|
||||
const message = `expected ${actual} to be within range ${floor}-${ceiling}`;
|
||||
return { message, pass };
|
||||
},
|
||||
|
||||
negativeCompare: (actual: any, floor: number, ceiling: number): jasmine.CustomMatcherResult => {
|
||||
const pass = actual < floor && actual > ceiling;
|
||||
const message = `expected ${actual} not to be within range ${floor}-${ceiling}`;
|
||||
return { message, pass };
|
||||
}
|
||||
};
|
||||
@@ -1011,6 +1017,14 @@ describe("Custom matcher: 'toBeGoofy'", () => {
|
||||
expect(2).toBeWithinRange(1, 3);
|
||||
});
|
||||
|
||||
it("can use the custom negativeCompare method", () => {
|
||||
const matcher = customMatchers["toBeWithinRange"](jasmine.matchersUtil, []);
|
||||
const result = matcher.negativeCompare!(1, 2, 3);
|
||||
|
||||
expect(result.pass).toBe(false);
|
||||
expect(result.message).toBe("expected 1 not to be within range 2-3");
|
||||
});
|
||||
|
||||
it("can be negated", () => {
|
||||
expect({
|
||||
hyuk: 'this is fun'
|
||||
|
||||
Reference in New Issue
Block a user