Skip to content

Commit

Permalink
test: added test case for yup.strip
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Jun 2, 2024
1 parent ef09aa6 commit 0b219b8
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/yup/tests/yup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,53 @@ test('reports required state for field-level schemas without a form context', as
}),
);
});

test('supports yup.strip', async () => {
const onSubmitSpy = vi.fn();
let onSubmit!: () => void;

const wrapper = mountWithHoc({
setup() {
const { handleSubmit } = useForm({
validationSchema: toTypedSchema(
yup.object({
test: yup.string().strip(),
name: yup.string(),
}),
),
});

const { value: test } = useField('test');
const { value: name } = useField('name');

// submit now
onSubmit = handleSubmit(onSubmitSpy);

return { test, name };
},
template: `
<div>
<input id="test" v-model="test" type="text">
<input id="name" v-model="name" type="text">
</div>
`,
});

await flushPromises();

const test = wrapper.$el.querySelector('#test');
const name = wrapper.$el.querySelector('#name');

setValue(test, '12345678');
setValue(name, '12345678');
await flushPromises();
onSubmit();
await flushPromises();
await expect(onSubmitSpy).toHaveBeenCalledTimes(1);
await expect(onSubmitSpy).toHaveBeenLastCalledWith(
expect.not.objectContaining({
test: expect.anything(),
}),
expect.anything(),
);
});

0 comments on commit 0b219b8

Please sign in to comment.