Skip to main content

Frontend, API and Data

Why This Matters

A bug always lives somewhere: in what the user sees, in the data that was sent, or in how that data was stored. Testers who understand how the parts fit together find the cause faster and write tests at the right level. You do not need to build these parts; you need a clear picture of them.

Three layers

TestRun Board in the browser: a table of seven test files with suite, status, duration and start time

LayerWhat it doesIn TestRun Board
FrontendWhat runs in the browser: the page, buttons, tablesThe React page you see above
APIThe agreed way for the frontend to ask for dataGET /api/runs returns the list of test runs as JSON
DataWhere information is storedIn a real product a database; in TestRun Board a fixture file, tests/mocks/data.ts

The browser (the client) sends a request to a server, and the server sends a response back. Everything you see on the page started as such a response.

Requests and responses

A request has a method (what you want to do) and a URL (what you want it done to):

MethodMeaningExample
GETRead somethingGET /api/runs
POSTCreate somethingPOST /api/runs with a new run
PUT / PATCHChange somethingPATCH /api/runs/r2
DELETERemove somethingDELETE /api/runs/r2

The response has a status code that says how it went. You will see these constantly:

The MDN reference page for HTTP response status codes, grouped into informational, successful, redirection, client error and server error responses

Screenshot of MDN Web Docs: HTTP response status codes.

  • 200 OK - it worked
  • 201 Created - something new was created
  • 400 Bad Request - the request was wrong
  • 401 / 403 - not logged in / not allowed
  • 404 Not Found - it does not exist
  • 500 Internal Server Error - the server failed

Where would you look for a bug?

SymptomFirst suspect
The table shows “1m 3s” instead of “1m 03s”Frontend logic (formatting)
The page says “Could not load test runs: GET /api/runs failed with 500”The API or the server
A test run shows the wrong statusThe data, or the API that returns it

TestRun Board’s own tests cover these cases: look at tests/runs-page.test.tsx, which checks the normal table, a loading message, an API error (500) and an empty list.

Exercise

  1. Start TestRun Board (npm run dev) and open it in Chrome or Edge.
  2. Open the developer tools (F12), go to the Network tab and reload the page. Find the request to /api/runs and look at its method, status code and response.
  3. Open tests/mocks/data.ts. Change the status of checkout.spec.ts from passed to failed, save, and reload the page. Which layer did you just change? Undo it with git restore tests/mocks/data.ts.

Key Takeaways

  • Frontend, API and data are three layers; bugs live in one of them.
  • A request has a method and a URL; a response has a status code and a body.
  • Learn the common status codes: 200, 201, 400, 401/403, 404, 500.
  • Knowing the layers tells you where to look and at which level to test.