Moved toHaveClass matcher into core so that it can be used in Karma
- Fixes #1503
This commit is contained in:
committed by
Gregg Van Hove
parent
8326ecf919
commit
11827572d3
@@ -21,6 +21,7 @@ getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
|
||||
'toHaveBeenCalledBefore',
|
||||
'toHaveBeenCalledTimes',
|
||||
'toHaveBeenCalledWith',
|
||||
'toHaveClass',
|
||||
'toMatch',
|
||||
'toThrow',
|
||||
'toThrowError',
|
||||
|
||||
33
src/core/matchers/toHaveClass.js
Normal file
33
src/core/matchers/toHaveClass.js
Normal file
@@ -0,0 +1,33 @@
|
||||
getJasmineRequireObj().toHaveClass = function(j$) {
|
||||
/**
|
||||
* {@link expect} the actual value to be a DOM element that has the expected class
|
||||
* @function
|
||||
* @name matchers#toHaveClass
|
||||
* @param {Object} expected - The class name to test for
|
||||
* @example
|
||||
* var el = document.createElement('div');
|
||||
* el.className = 'foo bar baz';
|
||||
* expect(el).toHaveClass('bar');
|
||||
*/
|
||||
function toHaveClass(util, customEqualityTesters) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
if (!isElement(actual)) {
|
||||
throw new Error(j$.pp(actual) + ' is not a DOM element');
|
||||
}
|
||||
|
||||
return {
|
||||
pass: actual.classList.contains(expected)
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function isElement(maybeEl) {
|
||||
return maybeEl &&
|
||||
maybeEl.classList &&
|
||||
j$.isFunction_(maybeEl.classList.contains);
|
||||
}
|
||||
|
||||
return toHaveClass;
|
||||
};
|
||||
Reference in New Issue
Block a user