Merge branch 'feature/matcher-toHaveClasses' of https://github.com/aYorky/jasmine
* Merges #2046 from @aYorky
This commit is contained in:
@@ -159,6 +159,7 @@ getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
|
||||
'toHaveBeenCalledTimes',
|
||||
'toHaveBeenCalledWith',
|
||||
'toHaveClass',
|
||||
'toHaveClasses',
|
||||
'toHaveSpyInteractions',
|
||||
'toMatch',
|
||||
'toThrow',
|
||||
@@ -6605,6 +6606,41 @@ getJasmineRequireObj().toHaveClass = function(j$) {
|
||||
return toHaveClass;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().toHaveClasses = function(j$) {
|
||||
/**
|
||||
* {@link expect} the actual value to be a DOM element that has the expected classes
|
||||
* @function
|
||||
* @name matchers#toHaveClasses
|
||||
* @since 5.6.0
|
||||
* @param {Object} expected - The class names to test for
|
||||
* @example
|
||||
* const el = document.createElement('div');
|
||||
* el.className = 'foo bar baz';
|
||||
* expect(el).toHaveClasses(['bar', 'baz']);
|
||||
*/
|
||||
function toHaveClasses(matchersUtil) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
if (!isElement(actual)) {
|
||||
throw new Error(matchersUtil.pp(actual) + ' is not a DOM element');
|
||||
}
|
||||
|
||||
return {
|
||||
pass: expected.every(e => actual.classList.contains(e))
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function isElement(maybeEl) {
|
||||
return (
|
||||
maybeEl && maybeEl.classList && j$.isFunction_(maybeEl.classList.contains)
|
||||
);
|
||||
}
|
||||
|
||||
return toHaveClasses;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().toHaveSize = function(j$) {
|
||||
/**
|
||||
* {@link expect} the actual size to be equal to the expected, using array-like length or object keys size.
|
||||
|
||||
Reference in New Issue
Block a user