summaryrefslogtreecommitdiff
path: root/spec/frontend/polyfills
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-20 15:07:34 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-20 15:07:34 +0000
commit8b61452138ecc511b52cd49be4ee6b8a80390c50 (patch)
tree122b817432c2a0f0e23767bd95791a89b20540c0 /spec/frontend/polyfills
parentf864f8a7aafa45b0e4c04e4312f89da4b1227c0f (diff)
downloadgitlab-ce-8b61452138ecc511b52cd49be4ee6b8a80390c50.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/polyfills')
-rw-r--r--spec/frontend/polyfills/element_spec.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/frontend/polyfills/element_spec.js b/spec/frontend/polyfills/element_spec.js
new file mode 100644
index 00000000000..64ce248ca44
--- /dev/null
+++ b/spec/frontend/polyfills/element_spec.js
@@ -0,0 +1,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();
+ });
+ });
+});