From 0a4fbcce9e8e3685496b1894685c7cba14082541 Mon Sep 17 00:00:00 2001 From: fi3ework Date: Wed, 24 Jun 2026 11:13:31 +0800 Subject: [PATCH] fix(rstest): use sync mock factory in mocking example rstest no longer supports async mock factories. Load the original module via the `with { rstest: 'importActual' }` import attribute and spread it into a sync factory instead. --- rstest/mocking/tests/dynamic-mock.test.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/rstest/mocking/tests/dynamic-mock.test.ts b/rstest/mocking/tests/dynamic-mock.test.ts index c7d57e218..d4cf57625 100644 --- a/rstest/mocking/tests/dynamic-mock.test.ts +++ b/rstest/mocking/tests/dynamic-mock.test.ts @@ -1,4 +1,5 @@ import { afterEach, beforeEach, describe, expect, it, rs, rstest } from '@rstest/core'; +import { formatDate as actualFormatDate } from '../src/utils' with { rstest: 'importActual' }; describe('rs.doMock() - Dynamic Module Mocking', () => { /** @@ -87,15 +88,10 @@ describe('rs.importActual() - Import Original Module', () => { */ it('should import actual module inside mock', async () => { - rs.doMock('../src/utils', async () => { - const actual = await rs.importActual('../src/utils'); - - return { - ...actual, - // Override only specific functions - generateId: () => 'overridden-id', - }; - }); + rs.doMock('../src/utils', () => ({ + formatDate: actualFormatDate, + generateId: () => 'overridden-id', + })); const utils = await import('../src/utils');