This will allow us to add support for custom object formatters, which will be a per-runable resource like custom matchers, by injecting them into the pretty-printer.
35 lines
883 B
JavaScript
35 lines
883 B
JavaScript
getJasmineRequireObj().toHaveClass = function(j$) {
|
|
/**
|
|
* {@link expect} the actual value to be a DOM element that has the expected class
|
|
* @function
|
|
* @name matchers#toHaveClass
|
|
* @since 3.0.0
|
|
* @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(matchersUtil) {
|
|
return {
|
|
compare: function(actual, expected) {
|
|
if (!isElement(actual)) {
|
|
throw new Error(matchersUtil.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;
|
|
};
|