Absolutely the best video I’ve found on testing an API. I plan on going back to the start and following along to really get a grasp on testing. Would be even better if you implement a little E2E testing.
@UdayKiranK-t9q3 ай бұрын
thank you for this tutorial, helped me understand the fundamentals of unit testing
@hashanhemachandra48322 жыл бұрын
Thanks so much for this tutorial Anson! Like Adam said, This is the best explanatory video I've ever seen on the internet on JEST testing! Love from Sri Lanka!
@StalkingPlagiarist2 жыл бұрын
Another awesome video, best explanation on testing I found so far on YT 🤘🤘🤘
@rady6546 Жыл бұрын
This is integration testing not unit because unit testing haven't side effect
@lovelesslol2 жыл бұрын
👍🙂 Thanks that will help a lot.
@learningforever2531 Жыл бұрын
Thanks for the sharing, Im just confusing why the object {id: 1, email: "..."} is wrapped in parenthesis ? Since I read the documentation in jest mockFn.mockImplementationOnce(fn) // where fn could be () => {// the code} So hope you or everyone could share the reason Here is the code in your video: User.mockImplementationOnce(() => ({id: 1, email: "..."} ))
@ansonthedev Жыл бұрын
Without the parenthesis, everything inside the curly braces, { }, would need to be statements. The parenthesis wrapping the curly braces indicates the return value is an object. It's a shorthand for doing this: () => { return { ... } }
@marshelaillon Жыл бұрын
What vsc theme are you using?
@ericsiddiq7634 Жыл бұрын
Thanks ❤
@pandagamedev11773 ай бұрын
what theme of vs did you use in this video
@AdnanDev-su5no7 ай бұрын
Hi there, how would you mock the User model in typescript ?
@ansonthedev7 ай бұрын
It's the same exact way, only difference is you will have TypeScript complaining about fields missing. If your user model is simple, you can just fill out all the fields. If it is complex and has a lot relations which end up with an object full of aggregated data (fields that map to objects), then you can either manually mock those objects too, or just mock the fields you need for the mock User and cast the object to a User manually to avoid TypeScript errors.
@AdnanDev-su5no6 ай бұрын
@@ansonthedev Thanks a lot Anson. Keep up the good work :). I've been following your NestJs playlist and it helped me clear the coding round of one of the interviews I appeared for.
@learningforever2531 Жыл бұрын
Hi, in case we use next() to forward to other middleware (e.g. errorHandler function) , how could we mock and verify the next function to be called with correct parameter ?
@ansonthedev Жыл бұрын
When you call next() inside the middleware function, remember that "next" function is a parameter passed to the middleware. So you would pass in a mocked function, e.g: const mockedNext = jest.fn(); Then you would assert that mockedNext was called, e.g: expect(mockedNext).toHaveBeenCalled() or expect(mockedNext).toHaveBeenCalledWith(...);