Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mariansimecek committed Jan 26, 2024
1 parent b4199ff commit fce540b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
7 changes: 6 additions & 1 deletion packages/@mantine/form/src/tests/insertListItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ describe('@mantine/form/insertListItem', () => {
);

act(() => hook.result.current.insertListItem('a', { b: 3 }, 1));
expect(spy).toHaveBeenCalledWith({ a: [{ b: 1 }, { b: 3 }, { b: 2 }] });
expect(spy).toHaveBeenCalledWith(
{ a: [{ b: 1 }, { b: 3 }, { b: 2 }] },
{
a: [{ b: 1 }, { b: 2 }],
}
);
});
});
5 changes: 4 additions & 1 deletion packages/@mantine/form/src/tests/removeListItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ describe('@mantine/form/removeListItem', () => {
);

act(() => hook.result.current.removeListItem('a', 1));
expect(spy).toHaveBeenCalledWith({ a: [{ b: 1 }, { b: 3 }] });
expect(spy).toHaveBeenCalledWith(
{ a: [{ b: 1 }, { b: 3 }] },
{ a: [{ b: 1 }, { b: 2 }, { b: 3 }] }
);
});
});
23 changes: 16 additions & 7 deletions packages/@mantine/form/src/tests/reorderListItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@ describe('@mantine/form/reorderListItem', () => {
);

act(() => hook.result.current.reorderListItem('a.1.b', { from: 1, to: 0 }));
expect(spy).toHaveBeenCalledWith({
a: [
{ b: [{ c: 1 }, { c: 2 }, { c: 3 }] },
{ b: [{ c: 5 }, { c: 4 }, { c: 6 }] },
{ b: [{ c: 7 }, { c: 8 }, { c: 9 }] },
],
});
expect(spy).toHaveBeenCalledWith(
{
a: [
{ b: [{ c: 1 }, { c: 2 }, { c: 3 }] },
{ b: [{ c: 5 }, { c: 4 }, { c: 6 }] },
{ b: [{ c: 7 }, { c: 8 }, { c: 9 }] },
],
},
{
a: [
{ b: [{ c: 1 }, { c: 2 }, { c: 3 }] },
{ b: [{ c: 4 }, { c: 5 }, { c: 6 }] },
{ b: [{ c: 7 }, { c: 8 }, { c: 9 }] },
],
}
);
});
});
8 changes: 4 additions & 4 deletions packages/@mantine/form/src/tests/values.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ describe('@mantine/form/values', () => {
const spy = jest.fn();
const hook = renderHook(() => useForm({ initialValues: { a: 1, b: 2 }, onValuesChange: spy }));
act(() => hook.result.current.setValues({ a: 3, b: 4 }));
expect(spy).toHaveBeenCalledWith({ a: 3, b: 4 });
expect(spy).toHaveBeenCalledWith({ a: 3, b: 4 }, { a: 1, b: 2 });
});

it('calls onValuesChange when setValues is called with function', () => {
const spy = jest.fn();
const hook = renderHook(() => useForm({ initialValues: { a: 1, b: 2 }, onValuesChange: spy }));
act(() => hook.result.current.setValues((current) => ({ ...current, a: 3 })));
expect(spy).toHaveBeenCalledWith({ a: 3, b: 2 });
expect(spy).toHaveBeenCalledWith({ a: 3, b: 2 }, { a: 1, b: 2 });
});

it('calls onValuesChange when setValues is called with values partial', () => {
const spy = jest.fn();
const hook = renderHook(() => useForm({ initialValues: { a: 1, b: 2 }, onValuesChange: spy }));
act(() => hook.result.current.setValues({ a: 3 }));
expect(spy).toHaveBeenCalledWith({ a: 3, b: 2 });
expect(spy).toHaveBeenCalledWith({ a: 3, b: 2 }, { a: 1, b: 2 });
});

it('calls onValuesChange when setFieldValue is called', () => {
const spy = jest.fn();
const hook = renderHook(() => useForm({ initialValues: { a: 1, b: 2 }, onValuesChange: spy }));
act(() => hook.result.current.setFieldValue('a', 3));
expect(spy).toHaveBeenCalledWith({ a: 3, b: 2 });
expect(spy).toHaveBeenCalledWith({ a: 3, b: 2 }, { a: 1, b: 2 });
});
});

0 comments on commit fce540b

Please sign in to comment.