Unit testing
Course: Integration and End to End testing - chapter 1
Code for today - https://github.com/100xdevs-cohort-2/week-25-integ-e2e-tests
Recap of Unit tests
Section titled “Recap of Unit tests”The following is a great example of a unit test - https://github.com/100xdevs-cohort-2/week-24-testing/tree/main/5-express-vitest-prisma
We have used concepts like
- Mocking
- mockingResolvedValue
- Spying to create unit tests for our simple express app.
app.post("/sum", async (req, res) => { const a = req.body.a; const b = req.body.b;
if (a > 1000000 || b > 1000000) { return res.status(422).json({ message: "Sorry we dont support big numbers" }) } const result = a + b;
const request = await prismaClient.request.create({ data: { a: a, b: b, answer: result, type: "Sum" } })
res.json({ answer: result, id: request.id });})$1b