Skip to content

Commit

Permalink
Fix Axios mocks in ToggleLocale.spec.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
julianguyen committed Nov 29, 2024
1 parent ee50bcc commit 966860b
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ describe('ToggleLocale', () => {
beforeEach(() => {
jest.spyOn(Cookies, 'get').mockImplementation(() => 'en');
jest.spyOn(Cookies, 'set');
jest.spyOn(axios, 'post').mockImplementation(() => Promise.resolve());
});

it('does nothing if the previous locale is the same as the selected', async () => {
const axiosPostSpy = jest.spyOn(axios, 'post').mockImplementation(() => Promise.resolve());
render(component);
await userEvent.selectOptions(screen.getByRole('combobox'), 'en');
expect(axios.post).not.toHaveBeenCalled();
expect(axiosPostSpy).not.toHaveBeenCalled();
});

it('sets the locale cookie and makes a post request if the selected locale is different from the previous', async () => {
const axiosPostSpy = jest.spyOn(axios, 'post').mockImplementation(() => Promise.resolve());
render(component);
await userEvent.selectOptions(screen.getByRole('combobox'), 'es');
expect(Cookies.set).toHaveBeenCalledWith('locale', 'es');
expect(axios.post).toHaveBeenCalledWith('/toggle_locale', {
expect(axiosPostSpy).toHaveBeenCalledWith('/toggle_locale', {
locale: 'es',
});
});
Expand Down

0 comments on commit 966860b

Please sign in to comment.