Skip to content

Commit 582294d

Browse files
fix: update FormData mock to properly implement MockedFormData interface
1 parent 94381bb commit 582294d

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

tests/resources/drafts.spec.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,30 @@ jest.mock('formdata-node', () => {
1010
return {
1111
FormData: jest.fn().mockImplementation(() => {
1212
const appendedData: Record<string, any> = {};
13-
const methods = {
14-
append: (key: string, value: any, _filename?: string) => {
13+
14+
const formData: MockedFormData = {
15+
append(key: string, value: any) {
1516
if (value && typeof value === 'object' && 'content' in value) {
1617
// Handle File objects
1718
appendedData[key] = value.content;
1819
} else {
1920
appendedData[key] = value;
2021
}
2122
},
22-
_getAppendedData: () => appendedData,
23+
_getAppendedData() {
24+
return appendedData;
25+
}
2326
};
2427

25-
// Create the base object with methods
26-
const formData = Object.create(Object.prototype, {
27-
...Object.getOwnPropertyDescriptors(methods),
28-
form: {
29-
get() {
30-
return formData;
31-
},
32-
configurable: true,
33-
enumerable: true,
34-
},
28+
// Create a proxy to handle form property access
29+
return new Proxy(formData, {
30+
get(target, prop) {
31+
if (prop === 'form') {
32+
return target;
33+
}
34+
return target[prop as keyof typeof target];
35+
}
3536
});
36-
37-
return formData;
3837
}),
3938
File: jest.fn().mockImplementation((content: any[], name: string) => ({
4039
content,

0 commit comments

Comments
 (0)