Skip to content

Commit 908c66e

Browse files
committed
Add unit test for parseElementOrSelector
1 parent ef10103 commit 908c66e

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

test/unit/utils/general.spec.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Step } from '../../../src/js/step.js';
2-
import { getPopperOptions, parseAttachTo } from '../../../src/js/utils/general.js';
2+
import { getPopperOptions, parseAttachTo, parseElementOrSelector } from '../../../src/js/utils/general.js';
33

44
describe('General Utils', function() {
55
let optionsElement;
@@ -25,6 +25,30 @@ describe('General Utils', function() {
2525
});
2626
});
2727

28+
describe('parseElementOrSelector()', function() {
29+
it('Returns the same HTMLElement passed to it', function () {
30+
const element = document.createElement('div');
31+
const parsedElement = parseElementOrSelector(element);
32+
expect(element === parsedElement).toBeTruthy();
33+
});
34+
35+
it('Returns an HTMLElement when passed a matching selector', function() {
36+
const parsedElement = parseElementOrSelector('.options-test');
37+
expect(parsedElement).toBeInstanceOf(window.HTMLElement);
38+
});
39+
40+
it('Returns null when passed a non-matching selector', function() {
41+
const parsedElement = parseElementOrSelector('.element-does-not-exist');
42+
expect(parsedElement).toBeNull();
43+
});
44+
45+
it('Returns null when passed falsy values', function() {
46+
expect(parseElementOrSelector(undefined)).toBeNull();
47+
expect(parseElementOrSelector(false)).toBeNull();
48+
expect(parseElementOrSelector(null)).toBeNull();
49+
});
50+
});
51+
2852
describe('getPopperOptions', function() {
2953
it('modifiers can be overridden', function() {
3054
const step = new Step({}, {

0 commit comments

Comments
 (0)