Commit b4984d1
committed
fix(test): ensure useEncryption hook and test share same crypto module instance
In Vitest's jsdom environment, a static import inside a hook (captured
at module evaluation time) and a dynamic import() inside a test body
can resolve to different module instances. When vi.stubGlobal patches
crypto after static imports have already been evaluated, the hook's
closed-over decryptContent has a stale crypto reference (no .subtle),
while the test's dynamic import() gets the patched one.
Fix: use vi.mock + vi.importActual so both the test's enc() helper
and the hook's internal decryptContent are guaranteed to come from
the same module instance, with the same crypto reference.1 parent 7353085 commit b4984d1
1 file changed
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
6 | 14 | | |
7 | 15 | | |
8 | 16 | | |
| |||
0 commit comments