JEST Assignment- 4
Basic Questions
- Write a test that runs 5 test cases in parallel using Jest.
- Write a test that fails when two tests share a mock function (without clearAllMocks).
- Write a test that uses jest.clearAllMocks() to reset mock call counts.
- Write a test that uses jest.resetAllMocks() to reset mock implementations.
- Write a test that groups tests into multiple describe blocks for clarity.
- Write a test that dynamically imports a utility function using await import().
- Write a test that checks two modules do not leak mocks into each other.
- Write a test that verifies resetting mocks does not affect other test suites.
- Write a test that imports a dynamic module only inside a test case.
- Write a test for a React component wrapped in ErrorBoundary to show fallback on error.
- Write a test that throws an error inside a component and ensures fallback UI renders.
- Write a test that simulates a network error with Axios and checks “Error loading” message.
- Write a test that validates fallback UI is replaced when error is fixed.
- Write a test that triggers a timeout error in a promise and checks handling.
- Write a test that prints debug info using console.log inside a failing test.
- Write a test that runs with –detectOpenHandles and fixes an async leak.
- Write a test that simulates jsdom error (e.g., missing window.fetch) and mocks it.
- Write a test using debugger; statement in Jest test and ensure it halts.
- Write a test that runs with –runInBand and ensures sequential execution.
- Write a test that validates basic usage of Jest VSCode debugger (using debugger;).
Intermediate Questions
- Write an integration test for a Redux reducer + React component that updates state on button click.
- Write an integration test for a Vuex store action updating component UI.
- Write an integration test where React component dispatches an async Redux action (API call).
- Write a test for combined components (Parent + Child) where child updates parent state.
- Write an integration test for a login flow (enter username, password → call API → show dashboard).
- Write an integration test that simulates API failure during login and shows error message.
- Write an integration test for an HTTP request + UI flow in Next.js API route.
- Write a test that checks end-to-end flow with Puppeteer visiting a login page.
- Write an E2E test with Puppeteer filling and submitting a form.
- Write an E2E test that mocks user navigation between two pages.
- Write an E2E test with Playwright that verifies button click updates DOM.
- Write an E2E test with Puppeteer mocking API response.
- Write an E2E test with Playwright simulating invalid form submission.
- Write an integration test for component + custom hook (useAuth) combined.
- Write a test for a fallback component that loads when API is down.
- Write a test that uses jest.spyOn(console, “error”) to silence React error boundary logs.
- Write an integration test for Express.js API + Mongoose model (mocked DB).
- Write a test that simulates retry on API failure with mocked responses.
- Write a test for a multi-step form component (Step 1 → Step 2 → Step 3).
- Write a test that uses Jest snapshots to capture combined component tree.
Advanced Questions
- Write an E2E test with Puppeteer that logs into an app, navigates to profile, and verifies username.
- Write an E2E test with Playwright that uploads a file and checks success message.
- Write an integration test for Redux + API + UI where API success updates state + DOM.
- Write an integration test for Redux + API + UI where API error updates state + error DOM.
- Write an integration test for a React ErrorBoundary + Async API component combined.
- Write an E2E test with Puppeteer that simulates invalid login → shows “Invalid Credentials”.
- Write an E2E test with Playwright that simulates cart checkout flow (Add → Checkout → Success).
- Write an advanced test that uses jest.resetModules() to isolate imports across tests.
- Write a test that runs Jest with –detectOpenHandles and finds a hanging Promise, then fixes it.
- Write a hybrid test (Integration + E2E) where Playwright fills a form → submits → backend mocked with Jest → success UI rendered.