blob: 64ce248ca44e7f245379150fe643aac3a421771e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
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();
});
});
});
|