debian-mirror-gitlab/spec/javascripts/lib/utils/dom_utils_spec.js
2017-09-10 17:25:29 +05:30

35 lines
947 B
JavaScript

import { addClassIfElementExists } from '~/lib/utils/dom_utils';
describe('DOM Utils', () => {
describe('addClassIfElementExists', () => {
const className = 'biology';
const fixture = `
<div class="parent">
<div class="child"></div>
</div>
`;
let parentElement;
beforeEach(() => {
setFixtures(fixture);
parentElement = document.querySelector('.parent');
});
it('adds class if element exists', () => {
const childElement = parentElement.querySelector('.child');
expect(childElement).not.toBe(null);
addClassIfElementExists(childElement, className);
expect(childElement.classList).toContain(className);
});
it('does not throw if element does not exist', () => {
const childElement = parentElement.querySelector('.other-child');
expect(childElement).toBe(null);
addClassIfElementExists(childElement, className);
});
});
});