Skip to content

Commit 7580560

Browse files
gooddaytodaykiselev
authored andcommitted
Added test to check waiting for element added later
1 parent 2273565 commit 7580560

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/index.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,44 @@ describe("intro", () => {
177177
expect(intro._introItems[step].element).toBe(laterAddedEl);
178178
});
179179

180+
test("should wait for element added after calling nextStep", (done) => {
181+
const onbeforechangedMock = jest.fn();
182+
const latterAddedElId = "later_added";
183+
var laterAddedEl;
184+
var stepCounter = 0;
185+
const intro = introJs()
186+
.setOptions({
187+
steps: [
188+
{
189+
intro: "step one",
190+
},
191+
{
192+
intro: "later aded",
193+
element: "#" + latterAddedElId,
194+
},
195+
],
196+
})
197+
.onchange(function (el) {
198+
if (el && stepCounter === 1) expect(el).toBe(laterAddedEl);
199+
stepCounter++;
200+
})
201+
.onbeforechange(onbeforechangedMock)
202+
.start();
203+
204+
intro.nextStep();
205+
206+
laterAddedEl = appendDummyElement();
207+
laterAddedEl.setAttribute("id", latterAddedElId);
208+
209+
expect(onbeforechangedMock).toBeCalledTimes(2);
210+
211+
const step = intro.currentStep();
212+
expect(step).toBe(1);
213+
expect(intro._introItems[step].element).toBe(laterAddedEl);
214+
// waitForElement waits with waitForElementByTimeout cause there is no MutationObserver in JSDom, so we need to wait a bit longer than waitForElementByTimeout
215+
setTimeout(done, 11500);
216+
}, 15000);
217+
180218
test("should highlight the target element", () => {
181219
const p = appendDummyElement();
182220

0 commit comments

Comments
 (0)