Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-async-leaks-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sanity/document-internationalization": patch
---

Fix async leaks in DocumentInternationalizationMenu tests by using fake timers to flush framer-motion animation Promises
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"turbo": "^2.8.2",
"typescript": "catalog:",
"validate-npm-package-name": "^7.0.2",
"vitest": "^4.0.18",
"vitest": "4.1.0-beta.5",
"vitest-package-exports": "^1.1.2"
},
"lint-staged": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('DocumentInternationalizationMenu', () => {
const articleSchemaType = schema.get('article') as ObjectSchemaType

beforeEach(() => {
vi.useFakeTimers({shouldAdvanceTime: true})
vi.mocked(useDocumentInternationalizationContext).mockReturnValue(MOCK_PLUGIN_CONFIG)
vi.mocked(useTranslationMetadata).mockReturnValue({
data: [],
Expand All @@ -73,9 +74,16 @@ describe('DocumentInternationalizationMenu', () => {
})
})

afterEach(() => {
afterEach(async () => {
// Advance timers to flush pending framer-motion animation Promises
// that would otherwise leak (MotionValue.start creates Promises
// resolved only on animation completion)
await vi.advanceTimersByTimeAsync(1000)
cleanup()
// Advance again in case cleanup triggered exit animations
await vi.advanceTimersByTimeAsync(1000)
vi.clearAllMocks()
vi.useRealTimers()
})

test('returns null when documentId is empty', () => {
Expand Down
Loading