| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fdae57f commit 7eaeba4
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -139,7 +139,7 @@ async function createSourceFromMock(mock, format) { | |||
| 139 | 139 | const { exportNames, hasDefaultExport, url } = mock; | |
| 140 | 140 | const useESM = format === 'module' || format === 'module-typescript'; | |
| 141 | 141 | const source = `${testImportSource(useESM)} | |
| 142 | - if (!$__test.mock._mockExports.has('${url}')) { | ||
| 142 | + if (!$__test.mock._mockExports.has(${JSONStringify(url)})) { | ||
| 143 | 143 | throw new Error(${JSONStringify(`mock exports not found for "${url}"`)}); | |
| 144 | 144 | } | |
| 145 | 145 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + export let string = 'original esm string'; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -413,6 +413,15 @@ test('modules cannot be mocked multiple times at once', async (t) => { | |||
| 413 | 413 | t.mock.module(fixture, { namedExports: { fn() { return 42; } } }); | |
| 414 | 414 | await assert.rejects(import(fixture), { code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME' }); | |
| 415 | 415 | }); | |
| 416 | + | ||
| 417 | + await t.test('Importing a module with a quote in its URL should work', async (t) => { | ||
| 418 | + const fixture = fixtures.fileURL('module-mocking', 'don\'t-open.mjs'); | ||
| 419 | + t.mock.module(fixture, { namedExports: { fn() { return 42; } } }); | ||
| 420 | + | ||
| 421 | + const mocked = await import(fixture); | ||
| 422 | + | ||
| 423 | + assert.strictEqual(mocked.fn(), 42); | ||
| 424 | + }); | ||
| 416 | 425 | }); | |
| 417 | 426 | ||
| 418 | 427 | test('mocks are automatically restored', async (t) => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments