Skip to content

Commit

Permalink
Replace deprecated Jest methods with the new methods (#3005)
Browse files Browse the repository at this point in the history
* replace deprecated `lastCalledWith` with `toHaveBeenLastCalledWith`

* replace deprecated `toThrowError` with `toThrow`
  • Loading branch information
RobinMalfait committed Feb 21, 2024
1 parent a50be92 commit 043edb8
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 36 deletions.
Expand Up @@ -98,7 +98,7 @@ describe('safeguards', () => {
])(
'should error when we are using a <%s /> without a parent <Combobox />',
suppressConsoleLogs((name, Component) => {
expect(() => render(Component)).toThrowError(
expect(() => render(Component)).toThrow(
`<${name} /> is missing a parent <Combobox /> component.`
)
})
Expand Down Expand Up @@ -6079,7 +6079,7 @@ describe('Form compatibility', () => {
// Submit the form
await click(getByText('Submit'))

expect(submits).lastCalledWith([['delivery', 'pickup']])
expect(submits).toHaveBeenLastCalledWith([['delivery', 'pickup']])
})

it('should be possible to submit a form with a value', async () => {
Expand Down Expand Up @@ -6119,7 +6119,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([]) // no data
expect(submits).toHaveBeenLastCalledWith([]) // no data

// Open combobox again
await click(getComboboxButton())
Expand All @@ -6131,7 +6131,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([['delivery', 'home-delivery']])
expect(submits).toHaveBeenLastCalledWith([['delivery', 'home-delivery']])

// Open combobox again
await click(getComboboxButton())
Expand All @@ -6143,7 +6143,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([['delivery', 'pickup']])
expect(submits).toHaveBeenLastCalledWith([['delivery', 'pickup']])
})

it('should not submit the data if the Combobox is disabled', async () => {
Expand Down Expand Up @@ -6248,7 +6248,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([
expect(submits).toHaveBeenLastCalledWith([
['delivery[id]', '1'],
['delivery[value]', 'pickup'],
['delivery[label]', 'Pickup'],
Expand All @@ -6265,7 +6265,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([
expect(submits).toHaveBeenLastCalledWith([
['delivery[id]', '2'],
['delivery[value]', 'home-delivery'],
['delivery[label]', 'Home delivery'],
Expand All @@ -6282,7 +6282,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([
expect(submits).toHaveBeenLastCalledWith([
['delivery[id]', '1'],
['delivery[value]', 'pickup'],
['delivery[label]', 'Pickup'],
Expand Down
Expand Up @@ -92,7 +92,7 @@ describe('Safe guards', () => {
])(
'should error when we are using a <%s /> without a parent <Dialog />',
suppressConsoleLogs((name, Component) => {
expect(() => render(Component)).toThrowError(
expect(() => render(Component)).toThrow(
`<${name} /> is missing a parent <Dialog /> component.`
)
expect.hasAssertions()
Expand Down
Expand Up @@ -32,7 +32,7 @@ describe('Safe guards', () => {
])(
'should error when we are using a <%s /> without a parent <Disclosure />',
suppressConsoleLogs((name, Component) => {
expect(() => render(Component)).toThrowError(
expect(() => render(Component)).toThrow(
`<${name} /> is missing a parent <Disclosure /> component.`
)
})
Expand Down
16 changes: 8 additions & 8 deletions packages/@headlessui-vue/src/components/listbox/listbox.test.tsx
Expand Up @@ -74,7 +74,7 @@ describe('safeguards', () => {
])(
'should error when we are using a <%s /> without a parent <Listbox />',
suppressConsoleLogs((name, Component) => {
expect(() => render(Component)).toThrowError(
expect(() => render(Component)).toThrow(
`<${name} /> is missing a parent <Listbox /> component.`
)
})
Expand Down Expand Up @@ -5005,7 +5005,7 @@ describe('Form compatibility', () => {
// Submit the form
await click(getByText('Submit'))

expect(submits).lastCalledWith([['delivery', 'pickup']])
expect(submits).toHaveBeenLastCalledWith([['delivery', 'pickup']])
})

it('should be possible to submit a form with a value', async () => {
Expand Down Expand Up @@ -5044,7 +5044,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([]) // no data
expect(submits).toHaveBeenLastCalledWith([]) // no data

// Open listbox again
await click(getListboxButton())
Expand All @@ -5056,7 +5056,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([['delivery', 'home-delivery']])
expect(submits).toHaveBeenLastCalledWith([['delivery', 'home-delivery']])

// Open listbox again
await click(getListboxButton())
Expand All @@ -5068,7 +5068,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([['delivery', 'pickup']])
expect(submits).toHaveBeenLastCalledWith([['delivery', 'pickup']])
})

it('should not submit the data if the Listbox is disabled', async () => {
Expand Down Expand Up @@ -5171,7 +5171,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([
expect(submits).toHaveBeenLastCalledWith([
['delivery[id]', '1'],
['delivery[value]', 'pickup'],
['delivery[label]', 'Pickup'],
Expand All @@ -5188,7 +5188,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([
expect(submits).toHaveBeenLastCalledWith([
['delivery[id]', '2'],
['delivery[value]', 'home-delivery'],
['delivery[label]', 'Home delivery'],
Expand All @@ -5205,7 +5205,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([
expect(submits).toHaveBeenLastCalledWith([
['delivery[id]', '1'],
['delivery[value]', 'pickup'],
['delivery[label]', 'Pickup'],
Expand Down
4 changes: 1 addition & 3 deletions packages/@headlessui-vue/src/components/menu/menu.test.tsx
Expand Up @@ -63,9 +63,7 @@ describe('Safe guards', () => {
])(
'should error when we are using a <%s /> without a parent <Menu />',
suppressConsoleLogs((name, component) => {
expect(() => render(component)).toThrowError(
`<${name} /> is missing a parent <Menu /> component.`
)
expect(() => render(component)).toThrow(`<${name} /> is missing a parent <Menu /> component.`)
})
)

Expand Down
Expand Up @@ -45,7 +45,7 @@ describe('Safe guards', () => {
])(
'should error when we are using a <%s /> without a parent <Popover />',
suppressConsoleLogs((name, Component) => {
expect(() => render(Component)).toThrowError(
expect(() => render(Component)).toThrow(
`<${name} /> is missing a parent <Popover /> component.`
)
})
Expand Down
Expand Up @@ -43,7 +43,7 @@ describe('Safe guards', () => {
it.each([['RadioGroupOption', RadioGroupOption]])(
'should error when we are using a <%s /> without a parent <RadioGroup />',
suppressConsoleLogs((name, Component) => {
expect(() => render(Component)).toThrowError(
expect(() => render(Component)).toThrow(
`<${name} /> is missing a parent <RadioGroup /> component.`
)
})
Expand Down Expand Up @@ -1623,7 +1623,7 @@ describe('Form compatibility', () => {
// Submit the form
await click(getByText('Submit'))

expect(submits).lastCalledWith([['delivery', 'pickup']])
expect(submits).toHaveBeenLastCalledWith([['delivery', 'pickup']])
})
)

Expand Down Expand Up @@ -1659,7 +1659,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([]) // no data
expect(submits).toHaveBeenLastCalledWith([]) // no data

// Choose home delivery
await click(getByText('Home delivery'))
Expand All @@ -1668,7 +1668,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([['delivery', 'home-delivery']])
expect(submits).toHaveBeenLastCalledWith([['delivery', 'home-delivery']])

// Choose pickup
await click(getByText('Pickup'))
Expand All @@ -1677,7 +1677,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([['delivery', 'pickup']])
expect(submits).toHaveBeenLastCalledWith([['delivery', 'pickup']])
})

it('should not submit the data if the RadioGroup is disabled', async () => {
Expand Down Expand Up @@ -1771,7 +1771,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([
expect(submits).toHaveBeenLastCalledWith([
['delivery[id]', '1'],
['delivery[value]', 'pickup'],
['delivery[label]', 'Pickup'],
Expand All @@ -1785,7 +1785,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([
expect(submits).toHaveBeenLastCalledWith([
['delivery[id]', '2'],
['delivery[value]', 'home-delivery'],
['delivery[label]', 'Home delivery'],
Expand All @@ -1799,7 +1799,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([
expect(submits).toHaveBeenLastCalledWith([
['delivery[id]', '1'],
['delivery[value]', 'pickup'],
['delivery[label]', 'Pickup'],
Expand Down
10 changes: 5 additions & 5 deletions packages/@headlessui-vue/src/components/switch/switch.test.tsx
Expand Up @@ -845,7 +845,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([['notifications', 'on']])
expect(submits).toHaveBeenLastCalledWith([['notifications', 'on']])
})

it('should be possible to submit a form with an boolean value', async () => {
Expand Down Expand Up @@ -877,7 +877,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([]) // no data
expect(submits).toHaveBeenLastCalledWith([]) // no data

// Toggle
await click(getSwitchLabel())
Expand All @@ -886,7 +886,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([['notifications', 'on']])
expect(submits).toHaveBeenLastCalledWith([['notifications', 'on']])
})

it('should be possible to submit a form with a provided string value', async () => {
Expand Down Expand Up @@ -918,7 +918,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([]) // no data
expect(submits).toHaveBeenLastCalledWith([]) // no data

// Toggle
await click(getSwitchLabel())
Expand All @@ -927,7 +927,7 @@ describe('Form compatibility', () => {
await click(getByText('Submit'))

// Verify that the form has been submitted
expect(submits).lastCalledWith([['fruit', 'apple']])
expect(submits).toHaveBeenLastCalledWith([['fruit', 'apple']])
})

it('should not submit the data if the Switch is disabled', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/@headlessui-vue/src/components/tabs/tabs.test.ts
Expand Up @@ -32,7 +32,7 @@ describe('safeguards', () => {
])(
'should error when we are using a <%s /> without a parent <TabGroup /> component',
suppressConsoleLogs((name, Component) => {
expect(() => render(Component)).toThrowError(
expect(() => render(Component)).toThrow(
`<${name} /> is missing a parent <TabGroup /> component.`
)
})
Expand Down

0 comments on commit 043edb8

Please sign in to comment.