Skip to content

Commit 8bcf5ab

Browse files
fix: update FormData mock to handle form property correctly
1 parent 46035ba commit 8bcf5ab

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

tests/resources/drafts.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ jest.mock('formdata-node', () => {
1010
return {
1111
FormData: jest.fn().mockImplementation(function(this: MockedFormData) {
1212
const appendedData: Record<string, any> = {};
13-
this.append = (key: string, value: any, _filename?: string) => {
14-
if (value && typeof value === 'object' && 'content' in value) {
15-
// Handle File objects
16-
appendedData[key] = value.content;
17-
} else {
18-
appendedData[key] = value;
19-
}
20-
};
21-
this._getAppendedData = () => appendedData;
22-
// Ensure the form property also has access to _getAppendedData
23-
(this as any).form = {
13+
const form = {
14+
append: (key: string, value: any, _filename?: string) => {
15+
if (value && typeof value === 'object' && 'content' in value) {
16+
// Handle File objects
17+
appendedData[key] = value.content;
18+
} else {
19+
appendedData[key] = value;
20+
}
21+
},
2422
_getAppendedData: () => appendedData,
2523
};
24+
Object.assign(this, form);
25+
(this as any).form = this;
2626
return this;
2727
}),
2828
File: jest.fn().mockImplementation((content: any[], name: string) => ({

0 commit comments

Comments
 (0)