Skip to content

Commit 1840400

Browse files
wbobeirnemonshan
authored andcommitted
Add unit test for parseElementOrSelector + rebase
1 parent 0c64d14 commit 1840400

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

test/unit/utils/general.spec.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { should } from 'chai';
22
import { spy } from 'sinon';
33
import { Step } from '../../../src/js/step.js';
44
import { Tour } from '../../../src/js/tour.js';
5-
import { getPopperOptions, parseAttachTo, shouldCenterStep } from '../../../src/js/utils/general.js';
5+
import { getPopperOptions, parseAttachTo, shouldCenterStep, parseElementOrSelector } from '../../../src/js/utils/general.js';
66

77
describe('General Utils', function() {
88
let optionsElement;
@@ -61,6 +61,30 @@ describe('General Utils', function() {
6161
});
6262
});
6363

64+
describe('parseElementOrSelector()', function() {
65+
it('Returns the same HTMLElement passed to it', function () {
66+
const element = document.createElement('div');
67+
const parsedElement = parseElementOrSelector(element);
68+
expect(element === parsedElement).toBeTruthy();
69+
});
70+
71+
it('Returns an HTMLElement when passed a matching selector', function() {
72+
const parsedElement = parseElementOrSelector('.options-test');
73+
expect(parsedElement).toBeInstanceOf(window.HTMLElement);
74+
});
75+
76+
it('Returns null when passed a non-matching selector', function() {
77+
const parsedElement = parseElementOrSelector('.element-does-not-exist');
78+
expect(parsedElement).toBeNull();
79+
});
80+
81+
it('Returns null when passed falsy values', function() {
82+
expect(parseElementOrSelector(undefined)).toBeNull();
83+
expect(parseElementOrSelector(false)).toBeNull();
84+
expect(parseElementOrSelector(null)).toBeNull();
85+
});
86+
});
87+
6488
describe('getPopperOptions', function() {
6589
it('modifiers can be overridden', function() {
6690
const step = new Step({}, {

0 commit comments

Comments
 (0)