@@ -2,7 +2,7 @@ import { should } from 'chai';
22import { spy } from 'sinon' ;
33import { Step } from '../../../src/js/step.js' ;
44import { 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
77describe ( '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