Skip to content

Commit c7a9cc6

Browse files
author
Rémi Hau
committed
fix: not call destroy on destroyed step
1 parent e256dcb commit c7a9cc6

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

shepherd.js/src/step.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
isElement,
66
isHTMLElement,
77
isFunction,
8-
isUndefined
8+
isUndefined,
9+
isNull
910
} from './utils/type-check.ts';
1011
import { bindAdvance } from './utils/bind.ts';
1112
import {
@@ -699,7 +700,7 @@ export class Step extends Evented {
699700
* @private
700701
*/
701702
_setupElements() {
702-
if (!isUndefined(this.el)) {
703+
if (!isUndefined(this.el) && !isNull(this.el)) {
703704
this.destroy();
704705
}
705706

shepherd.js/src/utils/type-check.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ export function isString<T>(value: T | string): value is string {
3737
export function isUndefined<T>(value: T | undefined): value is undefined {
3838
return value === undefined;
3939
}
40+
41+
/**
42+
* Checks if `value` is null.
43+
* @param value The param to check if it is null
44+
*/
45+
export function isNull<T>(value: T | undefined | null): value is null {
46+
return value === null;
47+
}

shepherd.js/test/unit/step.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,19 @@ describe('Tour | Step', () => {
441441
).toBeTruthy();
442442
});
443443

444+
it('not calls destroy on the step if the step was destroyed', () => {
445+
const step = new Step(tour, {});
446+
let destroyCalled = false;
447+
step.el = document.createElement('a');
448+
step.destroy();
449+
step.destroy = () => (destroyCalled = true);
450+
step._setupElements();
451+
expect(
452+
destroyCalled,
453+
'_setupElements method not called destroy if the step was destroyed'
454+
).toBeFalsy();
455+
});
456+
444457
it('calls destroy on the tooltip if it already exists', () => {
445458
const step = new Step(tour, {});
446459
let destroyCalled = false;

0 commit comments

Comments
 (0)