Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions shepherd.js/src/step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
isElement,
isHTMLElement,
isFunction,
isUndefined
isUndefined,
isNull
} from './utils/type-check.ts';
import { bindAdvance } from './utils/bind.ts';
import {
Expand Down Expand Up @@ -699,7 +700,7 @@ export class Step extends Evented {
* @private
*/
_setupElements() {
if (!isUndefined(this.el)) {
if (!isUndefined(this.el) && !isNull(this.el)) {
this.destroy();
}

Expand Down
8 changes: 8 additions & 0 deletions shepherd.js/src/utils/type-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ export function isString<T>(value: T | string): value is string {
export function isUndefined<T>(value: T | undefined): value is undefined {
return value === undefined;
}

/**
* Checks if `value` is null.
* @param value The param to check if it is null
*/
export function isNull<T>(value: T | undefined | null): value is null {
return value === null;
}
13 changes: 13 additions & 0 deletions shepherd.js/test/unit/step.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,19 @@ describe('Tour | Step', () => {
).toBeTruthy();
});

it('not calls destroy on the step if the step was destroyed', () => {
const step = new Step(tour, {});
let destroyCalled = false;
step.el = document.createElement('a');
step.destroy();
step.destroy = () => (destroyCalled = true);
step._setupElements();
expect(
destroyCalled,
'_setupElements method not called destroy if the step was destroyed'
).toBeFalsy();
});

it('calls destroy on the tooltip if it already exists', () => {
const step = new Step(tour, {});
let destroyCalled = false;
Expand Down