-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vue,scripts): support parallel triggers
- Loading branch information
Showing
5 changed files
with
90 additions
and
16 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
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
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,68 @@ | ||
import { describe, it } from 'vitest' | ||
import { createHead, useScript } from '@unhead/vue' | ||
import { ref, watch } from 'vue' | ||
import { useDom } from '../../fixtures' | ||
|
||
describe('unhead vue e2e scripts', () => { | ||
it('multiple active promise handles', async () => { | ||
const dom = useDom() | ||
const head = createHead({ | ||
document: dom.window.document, | ||
}) | ||
|
||
const isTrigger1Active = ref(false) | ||
const trigger1 = new Promise<void>((resolve) => { | ||
watch(isTrigger1Active, (val) => { | ||
if (val) { | ||
resolve() | ||
} | ||
}) | ||
}) | ||
|
||
const isTrigger2Active = ref(false) | ||
const trigger2 = new Promise<void>((resolve) => { | ||
watch(isTrigger2Active, (val) => { | ||
if (val) { | ||
resolve() | ||
} | ||
}) | ||
}) | ||
|
||
const { status } = useScript({ | ||
src: '//duplicate.script', | ||
}, { | ||
// leaving the page will stop the trigger from activating | ||
trigger: trigger1, | ||
head, | ||
}) | ||
|
||
const { status: status2, _triggerPromises } = useScript({ | ||
src: '//duplicate.script', | ||
}, { | ||
// leaving the page will stop the trigger from activating | ||
trigger: trigger2, | ||
head, | ||
}) | ||
|
||
// two promises pending | ||
expect(_triggerPromises).toMatchInlineSnapshot(` | ||
[ | ||
Promise {}, | ||
Promise {}, | ||
] | ||
`) | ||
|
||
// trigger using the first promise | ||
isTrigger1Active.value = true | ||
// wait next tick | ||
await new Promise<void>((resolve) => { | ||
setTimeout(() => { | ||
resolve() | ||
}, 25) | ||
}) | ||
|
||
// both should be loaded | ||
expect(status.value).toEqual('loading') | ||
expect(status2.value).toEqual('loading') | ||
}) | ||
}) |