Skip to content

Commit 71bfe95

Browse files
author
Meena
committed
Fix addStep and addSteps types (fixes #1988)
1 parent c511c27 commit 71bfe95

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/intro.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class IntroJs {
128128
return this;
129129
}
130130

131-
addStep(step: IntroStep) {
131+
addStep(step: Partial<IntroStep>) {
132132
if (!this._options.steps) {
133133
this._options.steps = [];
134134
}
@@ -138,7 +138,7 @@ export class IntroJs {
138138
return this;
139139
}
140140

141-
addSteps(steps: IntroStep[]) {
141+
addSteps(steps: Partial<IntroStep>[]) {
142142
if (!steps.length) return this;
143143

144144
for (let index = 0; index < steps.length; index++) {

tests/jest/core/steps.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { nextStep, previousStep } from "../../../src/core/steps";
22
import _showElement from "../../../src/core/showElement";
33
import { IntroJs } from "../../../src/intro";
4+
import introJs from "../../../src";
45

56
jest.mock("../../../src/core/showElement");
67
jest.mock("../../../src/core/exitIntro");
@@ -123,5 +124,39 @@ describe("steps", () => {
123124
expect(fnCompleteCallback).toBeCalledTimes(1);
124125
expect(fnCompleteCallback).toHaveBeenCalledWith(2, "end");
125126
});
127+
128+
test("should be able to add steps using addStep()", async () => {
129+
const intro = introJs();
130+
131+
intro.addStep({
132+
element: document.createElement("div"),
133+
intro: "test step",
134+
});
135+
136+
await intro.start();
137+
138+
expect(intro._introItems).toHaveLength(1);
139+
expect(intro._introItems[0].intro).toBe("test step");
140+
});
141+
142+
test("should be able to add steps using addSteps()", async () => {
143+
const intro = introJs();
144+
145+
intro.addSteps([
146+
{
147+
intro: "first step",
148+
},
149+
{
150+
element: document.createElement("div"),
151+
intro: "second step",
152+
},
153+
]);
154+
155+
await intro.start();
156+
157+
expect(intro._introItems).toHaveLength(2);
158+
expect(intro._introItems[0].intro).toBe("first step");
159+
expect(intro._introItems[1].intro).toBe("second step");
160+
});
126161
});
127162
});

0 commit comments

Comments
 (0)