Skip to content

Commit

Permalink
fix(tests): manually reset node:buffer File (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Mar 4, 2025
1 parent 313a6f7 commit 8211340
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/uploads.test.ts
Original file line number Diff line number Diff line change
@@ -74,21 +74,25 @@ describe('toFile', () => {
});

describe('missing File error message', () => {
let prevFile: unknown;
let prevGlobalFile: unknown;
let prevNodeFile: unknown;
beforeEach(() => {
// The file shim captures the global File object when it's first imported.
// Reset modules before each test so we can test the error thrown when it's undefined.
jest.resetModules();
const buffer = require('node:buffer');
// @ts-ignore
prevFile = globalThis.File;
prevGlobalFile = globalThis.File;
prevNodeFile = buffer.File;
// @ts-ignore
globalThis.File = undefined;
require('node:buffer').File = undefined;
buffer.File = undefined;
});
afterEach(() => {
// Clean up
// @ts-ignore
globalThis.File = prevFile;
globalThis.File = prevGlobalFile;
require('node:buffer').File = prevNodeFile;
jest.resetModules();
});

0 comments on commit 8211340

Please sign in to comment.