test(matchers): add support for toMatchPattern in tests
This commit is contained in:

committed by
Alex Eagle

parent
b691da26af
commit
169869a195
@ -55,6 +55,8 @@ class Expect extends gns.Expect {
|
||||
void toHaveCssStyle(styles) {
|
||||
gns.guinness.matchers.toBeTrue(elementContainsStyle(actual, styles));
|
||||
}
|
||||
void toMatchPattern(pattern) =>
|
||||
gns.guinness.matchers.toBeTrue(pattern.hasMatch(actual));
|
||||
void toImplement(expected) => toBeA(expected);
|
||||
void toBeNaN() =>
|
||||
gns.guinness.matchers.toBeTrue(double.NAN.compareTo(actual) == 0);
|
||||
@ -98,6 +100,8 @@ class NotExpect extends gns.NotExpect {
|
||||
void toHaveCssStyle(styles) {
|
||||
gns.guinness.matchers.toBeFalse(elementContainsStyle(actual, styles));
|
||||
}
|
||||
void toMatchPattern(pattern) =>
|
||||
gns.guinness.matchers.toBeFalse(pattern.hasMatch(actual));
|
||||
void toBeNull() => gns.guinness.matchers.toBeFalse(actual == null);
|
||||
Function get _expect => gns.guinness.matchers.expect;
|
||||
}
|
||||
|
@ -78,6 +78,15 @@ export interface NgMatchers extends jasmine.Matchers {
|
||||
*/
|
||||
toThrowErrorWith(expectedMessage: any): boolean;
|
||||
|
||||
/**
|
||||
* Expect a string to match the given regular expression.
|
||||
*
|
||||
* ## Example
|
||||
*
|
||||
* {@example testing/ts/matchers.ts region='toMatchPattern'}
|
||||
*/
|
||||
toMatchPattern(expectedMessage: any): boolean;
|
||||
|
||||
/**
|
||||
* Invert the matchers.
|
||||
*/
|
||||
@ -240,6 +249,21 @@ _global.beforeEach(function() {
|
||||
};
|
||||
},
|
||||
|
||||
toMatchPattern() {
|
||||
return {compare: buildError(false), negativeCompare: buildError(true)};
|
||||
|
||||
function buildError(isNot) {
|
||||
return function(actual, regex) {
|
||||
return {
|
||||
pass: regex.test(actual) == !isNot,
|
||||
get message() {
|
||||
return `Expected ${actual} ${isNot ? 'not ' : ''}to match ${regex.toString()}`;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
toImplement: function() {
|
||||
return {
|
||||
compare: function(actualObject, expectedInterface) {
|
||||
|
Reference in New Issue
Block a user