diff options
author | winh <winnie@gitlab.com> | 2017-06-27 20:37:30 +0200 |
---|---|---|
committer | winh <winnie@gitlab.com> | 2017-06-27 20:37:30 +0200 |
commit | 6ab12777bc9aa79f37859318bce07d6b5a67acd6 (patch) | |
tree | ee55d398857414a8e85e0b50011126be3f1c0d60 /spec | |
parent | a61eda78a7f7f7e52c4e2b9e3221cc1da37ccf9f (diff) | |
download | gitlab-ce-6ab12777bc9aa79f37859318bce07d6b5a67acd6.tar.gz |
Introduce addClassIfElementExists utilitywinh-no-current-user-search-bar
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/lib/utils/dom_utils_spec.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/javascripts/lib/utils/dom_utils_spec.js b/spec/javascripts/lib/utils/dom_utils_spec.js new file mode 100644 index 00000000000..867bf5912d1 --- /dev/null +++ b/spec/javascripts/lib/utils/dom_utils_spec.js @@ -0,0 +1,35 @@ +import { addClassIfElementExists } from '~/lib/utils/dom_utils'; + +describe('DOM Utils', () => { + describe('addClassIfElementExists', () => { + const className = 'biology'; + const fixture = ` + <div class="parent"> + <div class="child"></div> + </div> + `; + + let parentElement; + + beforeEach(() => { + setFixtures(fixture); + parentElement = document.querySelector('.parent'); + }); + + it('adds class if element exists', () => { + const childElement = parentElement.querySelector('.child'); + expect(childElement).not.toBe(null); + + addClassIfElementExists(childElement, className); + + expect(childElement.classList).toContain(className); + }); + + it('does not throw if element does not exist', () => { + const childElement = parentElement.querySelector('.other-child'); + expect(childElement).toBe(null); + + addClassIfElementExists(childElement, className); + }); + }); +}); |