Files
jasmine/spec/core/matchers/toHaveClassesSpec.js
Steve Gravrock 434575f49d Use one declaration per statement
The old style of merging all of a function's variable declarations into
a single statement made some sense back in the days of var, but there's
no reason to keep doing it now that we use const and let.
2026-03-11 06:30:46 -07:00

49 lines
1.7 KiB
JavaScript

describe('toHaveClasses', function() {
it('fails for a DOM element that lacks all the expected classes', function() {
const matcher = privateUnderTest.matchers.toHaveClasses();
const result = matcher.compare(
specHelpers.domHelpers.createElementWithClassName(''),
['foo', 'bar']
);
expect(result.pass).toBe(false);
});
it('passes for a DOM element that has all the expected classes', function() {
const matcher = privateUnderTest.matchers.toHaveClasses();
const el = specHelpers.domHelpers.createElementWithClassName('foo bar baz');
expect(matcher.compare(el, ['foo', 'bar']).pass).toBe(true);
});
it('fails for a DOM element that only has some matching classes', function() {
const matcher = privateUnderTest.matchers.toHaveClasses();
const el = specHelpers.domHelpers.createElementWithClassName('foo bar');
expect(matcher.compare(el, ['foo', 'can']).pass).toBe(false);
});
it('throws an exception when actual is not a DOM element', function() {
const matcher = privateUnderTest.matchers.toHaveClasses({
pp: privateUnderTest.makePrettyPrinter()
});
expect(function() {
matcher.compare('x', ['foo']);
}).toThrowError("'x' is not a DOM element");
expect(function() {
matcher.compare(undefined, ['foo']);
}).toThrowError('undefined is not a DOM element');
const textNode = specHelpers.domHelpers.document.createTextNode('');
expect(function() {
matcher.compare(textNode, ['foo']);
}).toThrowError('HTMLNode is not a DOM element');
expect(function() {
matcher.compare({ classList: '' }, ['foo']);
}).toThrowError("Object({ classList: '' }) is not a DOM element");
});
});