All jobs / Full-stack developer / Testing
Full-stack developer interview question · 0–1 years
You are writing your first tests for a POST endpoint. What do you actually assert?
The strongest answer
The status code, the shape and key fields of the response, that the record really changed in the database, and that bad input comes back as a validation error rather than a 500
Why it works
Exactly — status, body contract, persisted effect, and the unhappy path. Those four are what a consumer depends on.
What a good answer covers
- Assert the contract, not the code path.
- Status code and body shape.
- Check the data really changed.
- Test the invalid input too.
Answers that fall short
- Close, but not the strongest: That it returns 200 and the response body matches the example in the ticket
A good start, but a 200 with nothing written to the database still passes, and the error cases go untested. - Weak: That the handler was called with the right arguments by the test double
That asserts your mock rather than your API; the test stays green while the endpoint is broken. - Red flag: That it does not throw — if the call comes back at all, the endpoint works
“It did not crash” is not a contract: every wrong field and every missing write slips through it.
Who gets asked this
More Testing questions
- How do you keep the real API out of a component test without the test drifting from the real thing?
- Do you test this against a real database or against a mocked repository?
- How do you test the parts that are not a request — an incoming webhook and a nightly job?
- Someone deleted a required field and merged because the unit tests still passed. What should CI do?
- The end-to-end suite passes alone and fails when it runs in parallel. What is wrong with the test data, and…
- How do you stop the API from breaking the UI in CI?
- Where should the end-to-end suite run in CI — against shared staging, or against a stack built for the run?
- What would you run against production itself, and what must such a check never do?