diff options
author | Luke "Jared" Bennett <lbennett@gitlab.com> | 2016-11-25 15:23:47 +0000 |
---|---|---|
committer | Luke "Jared" Bennett <lbennett@gitlab.com> | 2016-12-02 12:10:11 +0000 |
commit | 63e2d6528e3213742656758fc065aa55601885c8 (patch) | |
tree | 3ce214989ed9b45c80e5eb649041e17bc521e9c3 /spec/javascripts/extensions | |
parent | 141593fa719778426823173cd89aec2601c6f9fe (diff) | |
download | gitlab-ce-63e2d6528e3213742656758fc065aa55601885c8.tar.gz |
Added element extensions spec for .matches and .closestadd-element-extensions-tests
Diffstat (limited to 'spec/javascripts/extensions')
-rw-r--r-- | spec/javascripts/extensions/element_spec.js.es6 | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/javascripts/extensions/element_spec.js.es6 b/spec/javascripts/extensions/element_spec.js.es6 new file mode 100644 index 00000000000..c5b86d35204 --- /dev/null +++ b/spec/javascripts/extensions/element_spec.js.es6 @@ -0,0 +1,38 @@ +/*= 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(); + }); + }); + }); +})(); |