Skip to content

Commit

Permalink
Added test to check waiting for element added later
Browse files Browse the repository at this point in the history
  • Loading branch information
gooddaytoday authored and kiselev committed Jul 7, 2022
1 parent 2273565 commit 7580560
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,44 @@ describe("intro", () => {
expect(intro._introItems[step].element).toBe(laterAddedEl);
});

test("should wait for element added after calling nextStep", (done) => {
const onbeforechangedMock = jest.fn();
const latterAddedElId = "later_added";
var laterAddedEl;
var stepCounter = 0;
const intro = introJs()
.setOptions({
steps: [
{
intro: "step one",
},
{
intro: "later aded",
element: "#" + latterAddedElId,
},
],
})
.onchange(function (el) {
if (el && stepCounter === 1) expect(el).toBe(laterAddedEl);
stepCounter++;
})
.onbeforechange(onbeforechangedMock)
.start();

intro.nextStep();

laterAddedEl = appendDummyElement();
laterAddedEl.setAttribute("id", latterAddedElId);

expect(onbeforechangedMock).toBeCalledTimes(2);

const step = intro.currentStep();
expect(step).toBe(1);
expect(intro._introItems[step].element).toBe(laterAddedEl);
// waitForElement waits with waitForElementByTimeout cause there is no MutationObserver in JSDom, so we need to wait a bit longer than waitForElementByTimeout
setTimeout(done, 11500);
}, 15000);

test("should highlight the target element", () => {
const p = appendDummyElement();

Expand Down

0 comments on commit 7580560

Please sign in to comment.