test(matchers): add support for toHaveClass in tests
This commit is contained in:
@ -100,6 +100,7 @@ class Expect extends gns.Expect {
|
||||
void toThrowError([message = ""]) => toThrowWith(message: message);
|
||||
void toThrowErrorWith(message) => expectException(this.actual, message);
|
||||
void toBePromise() => gns.guinness.matchers.toBeTrue(actual is Future);
|
||||
void toHaveCssClass(className) => gns.guinness.matchers.toBeTrue(DOM.hasClass(actual, className));
|
||||
void toImplement(expected) => toBeA(expected);
|
||||
void toBeNaN() =>
|
||||
gns.guinness.matchers.toBeTrue(double.NAN.compareTo(actual) == 0);
|
||||
@ -138,6 +139,7 @@ class NotExpect extends gns.NotExpect {
|
||||
|
||||
void toEqual(expected) => toHaveSameProps(expected);
|
||||
void toBePromise() => gns.guinness.matchers.toBeFalse(actual is Future);
|
||||
void toHaveCssClass(className) => gns.guinness.matchers.toBeFalse(DOM.hasClass(actual, className));
|
||||
void toBeNull() => gns.guinness.matchers.toBeFalse(actual == null);
|
||||
Function get _expect => gns.guinness.matchers.expect;
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ export interface NgMatchers extends jasmine.Matchers {
|
||||
toBePromise(): boolean;
|
||||
toBeAnInstanceOf(expected: any): boolean;
|
||||
toHaveText(expected: any): boolean;
|
||||
toHaveCssClass(expected: any): boolean;
|
||||
toImplement(expected: any): boolean;
|
||||
toContainError(expected: any): boolean;
|
||||
toThrowErrorWith(expectedMessage: any): boolean;
|
||||
@ -244,6 +245,21 @@ _global.beforeEach(function() {
|
||||
};
|
||||
},
|
||||
|
||||
toHaveCssClass: function() {
|
||||
return {compare: buildError(false), negativeCompare: buildError(true)};
|
||||
|
||||
function buildError(isNot) {
|
||||
return function(actual, className) {
|
||||
return {
|
||||
pass: DOM.hasClass(actual, className) == !isNot,
|
||||
get message() {
|
||||
return `Expected ${actual.outerHTML} ${isNot ? 'not ' : ''}to contain the CSS class "${className}"`;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
toContainError: function() {
|
||||
return {
|
||||
compare: function(actual, expectedText) {
|
||||
|
Reference in New Issue
Block a user