mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 23:37:04 +00:00
Merge pull request #22254 from JamieMason/jasmine-matchers
Jasmine matchers can accept many arguments
This commit is contained in:
Vendored
+2
-2
@@ -219,8 +219,8 @@ declare namespace jasmine {
|
||||
type CustomEqualityTester = (first: any, second: any) => boolean | void;
|
||||
|
||||
interface CustomMatcher {
|
||||
compare<T>(actual: T, expected: T): CustomMatcherResult;
|
||||
compare(actual: any, expected: any): CustomMatcherResult;
|
||||
compare<T>(actual: T, expected: T, ...args: any[]): CustomMatcherResult;
|
||||
compare(actual: any, ...expected: any[]): CustomMatcherResult;
|
||||
}
|
||||
|
||||
type CustomMatcherFactory = (util: MatchersUtil, customEqualityTesters: CustomEqualityTester[]) => CustomMatcher;
|
||||
|
||||
@@ -963,6 +963,15 @@ var customMatchers: jasmine.CustomMatcherFactories = {
|
||||
return result;
|
||||
}
|
||||
};
|
||||
},
|
||||
toBeWithinRange: (util: jasmine.MatchersUtil, customEqualityTesters: jasmine.CustomEqualityTester[]) => {
|
||||
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}`;
|
||||
return { message, pass };
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
// add the custom matchers to interface jasmine.Matchers via TypeScript declaration merging
|
||||
@@ -977,6 +986,7 @@ var customMatchers: jasmine.CustomMatcherFactories = {
|
||||
declare namespace jasmine {
|
||||
interface Matchers<T> {
|
||||
toBeGoofy(expected?: jasmine.Expected<T>): boolean;
|
||||
toBeWithinRange(expected?: jasmine.Expected<T>, floor?: number, ceiling?: number): boolean;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -997,6 +1007,10 @@ describe("Custom matcher: 'toBeGoofy'", () => {
|
||||
}).toBeGoofy({ hyuk: ' is fun' });
|
||||
});
|
||||
|
||||
it("can take many 'expected' parameters", () => {
|
||||
expect(2).toBeWithinRange(1, 3);
|
||||
});
|
||||
|
||||
it("can be negated", () => {
|
||||
expect({
|
||||
hyuk: 'this is fun'
|
||||
|
||||
Vendored
+2
-2
@@ -714,8 +714,8 @@ declare namespace jasmine {
|
||||
type CustomEqualityTester = (first: any, second: any) => boolean;
|
||||
|
||||
interface CustomMatcher {
|
||||
compare<T>(actual: T, expected: T): CustomMatcherResult;
|
||||
compare(actual: any, expected: any): CustomMatcherResult;
|
||||
compare<T>(actual: T, expected: T, ...args: any[]): CustomMatcherResult;
|
||||
compare(actual: any, ...expected: any[]): CustomMatcherResult;
|
||||
}
|
||||
|
||||
interface CustomMatcherResult {
|
||||
|
||||
Vendored
+2
-2
@@ -287,8 +287,8 @@ declare namespace jasmine {
|
||||
}
|
||||
|
||||
interface CustomMatcher {
|
||||
compare<T>(actual: T, expected: T): CustomMatcherResult;
|
||||
compare(actual: any, expected: any): CustomMatcherResult;
|
||||
compare<T>(actual: T, expected: T, ...args: any[]): CustomMatcherResult;
|
||||
compare(actual: any, ...expected: any[]): CustomMatcherResult;
|
||||
}
|
||||
|
||||
interface CustomMatcherResult {
|
||||
|
||||
Reference in New Issue
Block a user