Skip to content

Commit

Permalink
Fix form values
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz committed Jun 19, 2024
1 parent afa01aa commit c1f38b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/snaps-jest/src/internals/simulation/files.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { FileOptions } from '@metamask/snaps-jest';
import type { File } from '@metamask/snaps-sdk';
import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';
import type { VirtualFile } from '@metamask/snaps-utils';
Expand All @@ -8,6 +7,8 @@ import { readFile } from 'fs/promises';
import mime from 'mime';
import { basename, extname, resolve } from 'path';

import type { FileOptions } from '../../types';

/**
* Get a statically defined Snap file from an array of files.
*
Expand Down
13 changes: 13 additions & 0 deletions packages/snaps-jest/src/internals/simulation/interface.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,19 @@ describe('getFormValues', () => {
},
});
});

it('returns null values as null', () => {
const state = {
foo: null,
};

const result = getFormValues(state);

expect(result).toStrictEqual({
value: { foo: null },
files: {},
});
});
});

describe('clickElement', () => {
Expand Down
10 changes: 4 additions & 6 deletions packages/snaps-jest/src/internals/simulation/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,10 @@ export function getFormValues(state?: FormState): FormValues {
return Object.entries(state).reduce<FormValues>(
(accumulator, [key, value]) => {
const formValue = value as string | File | null;
if (formValue) {
if (typeof formValue === 'string') {
accumulator.value[key] = formValue;
} else {
accumulator.files[key] = formValue;
}
if (typeof formValue === 'string' || formValue === null) {
accumulator.value[key] = formValue;
} else {
accumulator.files[key] = formValue;
}

return accumulator;
Expand Down

0 comments on commit c1f38b8

Please sign in to comment.