debian-mirror-gitlab/spec/frontend/polyfills/element_spec.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-03-09 13:42:32 +05:30
import '~/commons/polyfills/element';
describe('Element polyfills', () => {
let testContext;
beforeEach(() => {
testContext = {};
});
beforeEach(() => {
testContext.element = document.createElement('ul');
});
describe('matches', () => {
it('returns true if element matches the selector', () => {
expect(testContext.element.matches('ul')).toBeTruthy();
});
it("returns false if element doesn't match the selector", () => {
expect(testContext.element.matches('.not-an-element')).toBeFalsy();
});
});
describe('closest', () => {
beforeEach(() => {
testContext.childElement = document.createElement('li');
testContext.element.appendChild(testContext.childElement);
});
it('returns the closest parent that matches the selector', () => {
expect(testContext.childElement.closest('ul').toString()).toBe(
testContext.element.toString(),
);
});
it('returns itself if it matches the selector', () => {
expect(testContext.childElement.closest('li').toString()).toBe(
testContext.childElement.toString(),
);
});
it('returns undefined if nothing matches the selector', () => {
expect(testContext.childElement.closest('.no-an-element')).toBeFalsy();
});
});
});