Testing Express REST API With Jest & Supertest

Testing Express REST API With Jest & Supertest

TomDoesTech

2 года назад

117,456 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Mohammed Sardar
Mohammed Sardar - 07.10.2023 13:40

Thank you. Any video for complex json object test cases scripts example in jest?

Ответить
Andrey Ruznyaev
Andrey Ruznyaev - 19.08.2023 23:07

Good content, but it's honestly really hard to watch, with everything jumping around on the screen. So please consider this, because it's really not easy on the eyes to consume your content, and it's hard to stay focused.

I haven't noticed that in your other videos though as much, but this one is kinda tough

I still hit that like button though, because there's still value in the video

Ответить
uptimizer prolife
uptimizer prolife - 19.06.2023 20:39

Good video! I watched it for the second time.

Ответить
uptimizer prolife
uptimizer prolife - 19.06.2023 20:27

Cool ❤❤❤❤❤❤

Ответить
brokeDeveloper
brokeDeveloper - 09.06.2023 17:35

Hi, great video. I have a question tho, how do I mock a class service?

Ответить
Majid Majid
Majid Majid - 30.04.2023 01:16

Hello, thanks a lot for this tuto!
I have a problem with using the send method for a post/put request, I always get an error "Right-hand side of 'instanceof' is not callable"
What is the reason of this error?

Ответить
PScoriae
PScoriae - 20.03.2023 19:22

I was absolutely clueless on how to mock my own functions. thank you so much

Ответить
Konrad
Konrad - 18.03.2023 13:22

Even if I mock the service for user it still calls mongodb and creates it in database. Any thoughts?

Ответить
Salman Rana
Salman Rana - 26.02.2023 20:55

Thanks for the awesom video. You made my TDD weekend fun.

Ответить
Narissa Tsuboi
Narissa Tsuboi - 16.02.2023 02:43

THANK YOU SO MUCH for making this video. I've been looking for a compare and contrast of mongo-memory-server and mocking services for quite awhile!

Ответить
Thomas Daugaard
Thomas Daugaard - 09.02.2023 19:41

Which extension are you using to get "intellisense"-isc behaviour in the terminal?
And also which extension to get the "Run | Debug" options over each "Describe"-block?

Ответить
Meet Koriya
Meet Koriya - 23.01.2023 13:26

can you please tell me which vs code extension you are using for highlighting the code block

Ответить
ayoub tahir
ayoub tahir - 21.01.2023 13:40

.set('Authorization', `Bearer ${jwt}`) not working any idea why?

Ответить
Dumbledoor Nguyen
Dumbledoor Nguyen - 04.12.2022 12:31

Hi Tom! Your authentication API video with typegoose and zod helped me tremendously. I know i will learn a lot from this, so Thank you for making this video!

Ответить
Aryan Rahman
Aryan Rahman - 18.11.2022 20:31

You're awesome!

Ответить
George Kusto
George Kusto - 09.11.2022 12:17

When testing api with ject, do you actually need to have data in database?

Ответить
Estifanos Neway
Estifanos Neway - 05.10.2022 15:13

really helpful and fun, thank you.

Ответить
Michael Umeokoli
Michael Umeokoli - 30.09.2022 06:20

I didn't enjoy this video as much as the last one the explanations were too brief it felt like you were just rushing true it also I did not really understand that last test so well. i don't have much experience in testing so maybe that is the problem. looking forward to the next video in the series. Thank you Tom.

Ответить
Michael Umeokoli
Michael Umeokoli - 30.09.2022 01:39

I keep getting a 403 on this test

describe("given the user is logged in ", () => {
it("should return a 200 and create product", async () => {
const jwt = signJwt(userPayload);

const { statusCode, body } = await supertest(app)
.post("/api/products")
.set("Authorization", `Bearer ${jwt}`)
.send(productPayload);

expect(statusCode).toBe(200);
expect(body).toEqual({});
});
});

everything works 100% on postman

Ответить
Shegun Adebimpe-Ojo
Shegun Adebimpe-Ojo - 29.09.2022 02:06

do you have a video with javascript and not typescript?

Ответить
Chris L
Chris L - 10.09.2022 23:20

Hi Tom, thanks for the video. With the updated repo, if you follow along to the video you will find that you will not be able to get most of the mongodb-memory-server section to work.

1. You will not be able to get product.productId after calling createProduct because productId doesn't exist in either the ProductDocument or ProductInput interface. To fix this I had to put productId: String in the ProductDocument interface, not sure if that is the right approach but the tests passed after that

2. You will not be able to use signJwt because it expects 2 parameters now, not sure how to get around this one. I skimmed through the rest of the video and didn't see any fixes for that so I stopped trying here.

Ответить
Harsh Patel
Harsh Patel - 26.08.2022 18:45

Late comment but for some reason Jest times out when i'm running all of the test after I included the "should return a 200 and create the product"... but if I just run that test individually with '.only' then it doesnt time out and passes. I even tried extending the time but it still times out when running all of the tests.

Ответить
Bahman Asheghi
Bahman Asheghi - 25.08.2022 01:03

awesome tutorial🤌

Ответить
Tai Le
Tai Le - 06.08.2022 07:24

awesome video on testing with Jest

Ответить
Purvi Modi
Purvi Modi - 04.08.2022 13:55

Thanks you so much this video helped me a lot in braking the code and testing .

Ответить
Pete E
Pete E - 17.07.2022 08:16

Amazing tutorials as always, love your Typescript/Mongoose/Express series

Ответить
1D Forever
1D Forever - 15.07.2022 18:39

which terminal you are using in VSCode?

Ответить
PauwCrypto
PauwCrypto - 15.07.2022 00:43

Are these tests considered unit-tests or integration tests? I'm leaning towards unit-tests since there is not really a database interaction and you are only mocking a service. But what if in the service you make a call to the database and fetch some data, is it considered to be an integration test then?

Ответить
Arcan
Arcan - 17.06.2022 23:05

tldr version??

Ответить
Andrew M
Andrew M - 11.06.2022 05:45

great tutorial keep it up but why did you need ts-ignore on the mockReturnValue?

Ответить
Wra
Wra - 14.05.2022 05:40

This series is the best tutorial I've been following, thank you very much it is gold

Ответить
Marc
Marc - 12.05.2022 16:51

Thanks very much, great video. When testing 'user registration' for 'given username and password are valid', I kept getting a 'TypeError' => 'user.toJson is not a function' in the referencing user.controller.. I removed the toJson() from the omit function and test passed and the route still works without. Couldn't quite understand what the issue was? Testing removing toJson from the omit functions in user.service, the app broke on the spot.. tried JSON.stringify instead, he wasn't having it.. Anybody hat a similar problem? Tks, regards PS: just seeing now that in the controller the createUser() is called from where the user is returned through the omit function already... so in the controller I only return and send the user

Ответить
Ose Ughu
Ose Ughu - 30.04.2022 11:56

Hi! Great tutorial! Just wanted to ask what file icon theme are you using on vscode? thank you!

Ответить
Marko Kraljevic
Marko Kraljevic - 24.04.2022 18:31

why you dont use testing database? you are not testing much this way

Ответить
Marko Kraljevic
Marko Kraljevic - 23.04.2022 14:27

you didnt explain clearly what is the difference between clearMocks and resetMocks? and what is the difference between supertest and plain axios?

Ответить
Kim Shares
Kim Shares - 30.03.2022 16:58

is it possible for someone to replace where we used mongodb-memory-server with the real MongoDB server?

Ответить
Chris James
Chris James - 03.02.2022 02:38

Great testing video. Appreciate your time and effort with it. Found your channel a few weeks ago and have slowly been making my way through all the videos. :)

Ответить
Zack Bello
Zack Bello - 18.01.2022 10:44

This is awesome!!! thank you for this lesson. One request, can we make it a full stack app i.e. can we build a frontend to consume this API? thank you once again.

Ответить
Stvorenui
Stvorenui - 18.01.2022 09:54

Hello) I am writing the fourth comment)

Ответить
Tyler Wong
Tyler Wong - 07.01.2022 09:05

I keep getting "TypeError: (0 , supertest_1.default) is not a function." What's the problem here?

Ответить
Luis Alberto Sandoval Arevalo
Luis Alberto Sandoval Arevalo - 04.01.2022 21:38

Nice video.
I got a problem with this, inside config folder, test.ts file have the private key, if I remove the private key from test.ts file config and create the custom-environment-variables.ts file to read the variable from an env file, it doesn't work because can't read the private key value, if I just paste the private key into the test.ts file all work again, any idea or config I am missing there?

Ответить
Coding Training
Coding Training - 29.12.2021 11:45

if anyone uses NPM run this command " npm run test -- --watch "

Ответить
Jig kura
Jig kura - 16.11.2021 03:11

This channel is a gem! I appreciate that you cover important and practical topics (i.e testing, TS) in great detail. I've seen some videos on the 2 topics mentioned above but not as as it pertains to Nodejs. Thank you and you definitely deserve more views/subscribers.

Ответить
Arbër Hyseni
Arbër Hyseni - 04.11.2021 18:59

Hi Tom, first of all thank you for your dedication for wanting to help others. I wanted to ask you how would I do the same with testing the endpoint only, without controllers and services?

Ответить
mohamed youssef
mohamed youssef - 28.10.2021 06:36

Please show us how to make the React front end to this API

Ответить