test(matchers): add support for toMatchPattern in tests
This commit is contained in:
parent
b691da26af
commit
169869a195
|
@ -55,6 +55,8 @@ class Expect extends gns.Expect {
|
||||||
void toHaveCssStyle(styles) {
|
void toHaveCssStyle(styles) {
|
||||||
gns.guinness.matchers.toBeTrue(elementContainsStyle(actual, styles));
|
gns.guinness.matchers.toBeTrue(elementContainsStyle(actual, styles));
|
||||||
}
|
}
|
||||||
|
void toMatchPattern(pattern) =>
|
||||||
|
gns.guinness.matchers.toBeTrue(pattern.hasMatch(actual));
|
||||||
void toImplement(expected) => toBeA(expected);
|
void toImplement(expected) => toBeA(expected);
|
||||||
void toBeNaN() =>
|
void toBeNaN() =>
|
||||||
gns.guinness.matchers.toBeTrue(double.NAN.compareTo(actual) == 0);
|
gns.guinness.matchers.toBeTrue(double.NAN.compareTo(actual) == 0);
|
||||||
|
@ -98,6 +100,8 @@ class NotExpect extends gns.NotExpect {
|
||||||
void toHaveCssStyle(styles) {
|
void toHaveCssStyle(styles) {
|
||||||
gns.guinness.matchers.toBeFalse(elementContainsStyle(actual, 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);
|
void toBeNull() => gns.guinness.matchers.toBeFalse(actual == null);
|
||||||
Function get _expect => gns.guinness.matchers.expect;
|
Function get _expect => gns.guinness.matchers.expect;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,15 @@ export interface NgMatchers extends jasmine.Matchers {
|
||||||
*/
|
*/
|
||||||
toThrowErrorWith(expectedMessage: any): boolean;
|
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.
|
* 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() {
|
toImplement: function() {
|
||||||
return {
|
return {
|
||||||
compare: function(actualObject, expectedInterface) {
|
compare: function(actualObject, expectedInterface) {
|
||||||
|
|
|
@ -54,6 +54,14 @@ export function main() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("toMatchPAttern", () => {
|
||||||
|
it("should assert that a string matches a given pattern", () => {
|
||||||
|
expect("matias").toMatchPattern(/ias$/g);
|
||||||
|
expect("tobias").toMatchPattern(/ias$/g);
|
||||||
|
expect("joonas").not.toMatchPattern(/ias$/g);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('toEqual for Maps', () => {
|
describe('toEqual for Maps', () => {
|
||||||
it('should detect equality for same reference', () => {
|
it('should detect equality for same reference', () => {
|
||||||
var m1 = MapWrapper.createFromStringMap({'a': 1});
|
var m1 = MapWrapper.createFromStringMap({'a': 1});
|
||||||
|
|
Loading…
Reference in New Issue