Welcome to mirror list, hosted at ThFree Co, Russian Federation.

element_spec.js.es6 « extensions « javascripts « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fddd7600cb95aa0aa2693e055e2ed704b87df52b (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
require('../spec_helper');
require('extensions/element');

(() => {
  describe('Element extensions', function () {
    beforeEach(() => {
      this.element = document.createElement('ul');
    });

    describe('matches', () => {
      it('returns true if element matches the selector', () => {
        expect(this.element.matches('ul')).toBeTruthy();
      });

      it("returns false if element doesn't match the selector", () => {
        expect(this.element.matches('.not-an-element')).toBeFalsy();
      });
    });

    describe('closest', () => {
      beforeEach(() => {
        this.childElement = document.createElement('li');
        this.element.appendChild(this.childElement);
      });

      it('returns the closest parent that matches the selector', () => {
        expect(this.childElement.closest('ul').toString()).toBe(this.element.toString());
      });

      it('returns itself if it matches the selector', () => {
        expect(this.childElement.closest('li').toString()).toBe(this.childElement.toString());
      });

      it('returns undefined if nothing matches the selector', () => {
        expect(this.childElement.closest('.no-an-element')).toBeFalsy();
      });
    });
  });
})();