Skip to content

Commit

Permalink
Fix stringifyVariables for Files
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Mar 20, 2020
1 parent 954a715 commit 686e933
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/core/src/utils/stringifyVariables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@ it('throws for circular structures', () => {
}).toThrow();
});

it('stringifies date correctly', () => {
it('stringifies dates correctly', () => {
const date = new Date('2019-12-11T04:20:00');
expect(stringifyVariables(date)).toBe(date.toJSON());
});

it('stringifies files correctly', () => {
const file = new File([0] as any, 'test.js');
Object.defineProperty(file, 'lastModified', { value: 123 });

expect(stringifyVariables(file)).toBe(
stringifyVariables({
name: 'test.js',
lastModified: 123,
})
);
});
2 changes: 2 additions & 0 deletions packages/core/src/utils/stringifyVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const stringify = (x: any): string => {
return out;
} else if (seen.has(x)) {
throw new TypeError('Converting circular structure to JSON');
} else if (typeof File === 'function' && x instanceof File) {
return stringify({ name: x.name, lastModified: x.lastModified });
}

const keys = Object.keys(x).sort();
Expand Down

0 comments on commit 686e933

Please sign in to comment.