Skip to content

Commit

Permalink
Add test, explains extra code
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Sep 5, 2024
1 parent 8b9e3f9 commit 4bdec59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function elementReady(selector, {
return cachedPromise;
}

// Not necessary, it just acts faster and avoids cache/listener setup
if (stopOnDomReady && isDomReady(target)) {
const promise = Promise.resolve(getMatchingElement({target, selector, predicate}));
promise.stop = () => {};
Expand Down
8 changes: 8 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ test('check if element ready before dom loaded', async t => {
t.is(await elementCheck, element);
});

test('shop checking if DOM was already ready', async t => {
const elementCheck = elementReady('#no-gonna-get-us', {
stopOnDomReady: true,
});

t.is(await elementCheck, undefined);
});

test('check if element ready after timeout', async t => {
const elementCheck = elementReady('#cheezburger', {
stopOnDomReady: false,
Expand Down

0 comments on commit 4bdec59

Please sign in to comment.