Skip to content

Instantly share code, notes, and snippets.

@mieradi
Created March 30, 2024 23:34
Show Gist options
  • Select an option

  • Save mieradi/daf0861ffcfd1d40d3f05797b3cea0ef to your computer and use it in GitHub Desktop.

Select an option

Save mieradi/daf0861ffcfd1d40d3f05797b3cea0ef to your computer and use it in GitHub Desktop.
describe('Dashboard tests', () => {
test('Renders dashboard without', async () => {
server.use(getDashboardDataMock(); // first res
const { getByTestId } = render(<Dashboard />);
await waitFor(() => {
expect(getByTestId(/dashboard-trips/i)).toBeNull();
});
});
test('Renders dashboard with trips', async () => {
const { getByText, getAllByTestId } = render(<Dashboard />);
server.use(getDashboardDataMock(withTripsMock); // second res
await waitFor(() => {
expect(getByTestId(/dashboard-trips/i)).not.toBeNull();
});
});
import { server } from './mocks/server.js';
import { vi } from 'vitest';
beforeAll(() => {
server.listen({ onUnhandledRequest: 'bypass' });
});
beforeEach(() => {
vi.clearAllMocks();
apolloClient.cache.reset();
});
afterEach(() => {
server.resetHandlers();
cleanup();
vi.clearAllMocks();
apolloClient.cache.reset();
});
afterAll(() => {
server.close();
});
// server.ts
import { setupServer } from 'msw/node';
export const server = setupServer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment