-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for _waitForElementByTimeout function
- Loading branch information
kiselev
committed
Aug 8, 2022
1 parent
33e560b
commit d5eaf0d
Showing
2 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { _waitForElementByTimeout } from "../../src/util/waitForElement"; | ||
import { appendDummyElement } from "../helper"; | ||
|
||
describe("Testing _waitForElementByTimeout", () => { | ||
const interval = 100; | ||
const maxTimeout = 3000; | ||
|
||
test("Callback call even if element doesn't appear after timeout", (done) => { | ||
const callback = jest.fn(); | ||
_waitForElementByTimeout("#not_existed", callback, interval, maxTimeout); | ||
expect(callback).toBeCalledTimes(0); | ||
setTimeout(function () { | ||
expect(callback).toBeCalledTimes(1); | ||
done(); | ||
}, maxTimeout + interval); | ||
}); | ||
|
||
test("Callback should be called immediately if elements already exists", () => { | ||
const callback = jest.fn(); | ||
const id = "prev_created"; | ||
const el = appendDummyElement(); | ||
el.setAttribute("id", id); | ||
_waitForElementByTimeout("#" + id, callback, interval, maxTimeout); | ||
expect(callback).toBeCalledTimes(1); | ||
}); | ||
|
||
test("Callback must be called after the element appears", (done) => { | ||
const callback = jest.fn(); | ||
const id = "later_created"; | ||
_waitForElementByTimeout("#" + id, callback, interval, maxTimeout); | ||
expect(callback).toBeCalledTimes(0); | ||
const el = appendDummyElement(); | ||
el.setAttribute("id", id); | ||
setTimeout(function () { | ||
expect(callback).toBeCalledTimes(1); | ||
done(); | ||
}, interval); | ||
}); | ||
|
||
test("Check interval is bigger than maximum timeout", (done) => { | ||
_waitForElementByTimeout("#not_existed", done, 1000, 100); | ||
}); | ||
|
||
test("Check interval is equal to maximum timeout", (done) => { | ||
_waitForElementByTimeout("#not_existed", done, 1000, 1000); | ||
}); | ||
|
||
test("Check interval is zero", (done) => { | ||
_waitForElementByTimeout("#not_existed", done, 0, maxTimeout); | ||
}); | ||
|
||
test("Maximum timeout is zero", (done) => { | ||
_waitForElementByTimeout("#not_existed", done, interval, 0); | ||
}); | ||
|
||
test("Maximum timeout and interval are zero", (done) => { | ||
_waitForElementByTimeout("#not_existed", done, 0, 0); | ||
}); | ||
}); |