Тёмный
No video :(

Mocking a Database in Node with Jest 

Sam Meech-Ward
Подписаться 118 тыс.
Просмотров 67 тыс.
50% 1

Learn how to use jest mock functions to mock a database in an HTTP server.
🔗 Previous Videos:
Introduction to Writing Automated Tests With Jest: • Unit Testing in Javasc...
Introduction to TDD in JavaScript: • TDD in JavaScript | Te...
Testing Node Server with Jest and Supertest: • Testing Node Server wi...
Dependency Injection: • Dependency Injection i...
🔗 Text version:
sammeechward.c...
🔗 Code:
github.com/Sam...
🔗 Jest Mock Functions:
jestjs.io/docs...
🔗 Moar Links
My Website: www.sammeechwa...
Instagram: / meech_ward
Github: github.com/org...
TikTok: / meech.s.ward

Опубликовано:

 

5 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 52   
@CodingPuff
@CodingPuff 2 года назад
These videos should be more popular
@DannyBoy45855
@DannyBoy45855 Год назад
@SamMeechWard, your videos are great. Thank you so much! I'd waiting to see the next video in this series that you talked about : testing databases in Node. I'm sure you have more than enough project ideas, but that's one I'd love to see!
@youssefmohamed1618
@youssefmohamed1618 Год назад
Great series.. thank you really. Can you please make the remaining video you talked about ? 👀
@elijah4840
@elijah4840 Год назад
Agreed
@wichaisawangpongkasame9237
@wichaisawangpongkasame9237 2 года назад
I'm struggling with what should be tested in REST api and your vids really help me understand the idea of it neatly, thanks.
@hamzayousfi4275
@hamzayousfi4275 3 года назад
Great Playlist (y) looking forward to the next episode !
@rvind92g
@rvind92g 2 года назад
For a moment I thought they title of this implied that you were gonna make fun of a database
@learner246
@learner246 10 месяцев назад
best jest tutorial on youtube
@AwesomeEnterpriseInc
@AwesomeEnterpriseInc 3 года назад
I love Jest mock functions! Reminds me of `action` in Storybook. Saves a ton of time and trouble for the dev. Also, great video Sam!!
@AwesomeEnterpriseInc
@AwesomeEnterpriseInc 3 года назад
Also, is that your campus??
@SamMeechWard
@SamMeechWard 3 года назад
Yes it is. Completely empty right now so not bad for filming 🤗
@TiodaniPKM
@TiodaniPKM Год назад
This is indeed useful to test an API independently from the database, but what if I want to actually test my database functions without modifying the database the real application connects to? From the title I thought that the video was going to talk about this. I can think of some ways to do it, but it would be good if you'd shown an example of how this is done in a proper way.
@elkhoudiry
@elkhoudiry 3 года назад
Solid work, i watched and loved all of your videos regarding "testing" subject, thank you
@jimmyfitzsimmons7170
@jimmyfitzsimmons7170 3 года назад
Hi guy, very helpfull but I don't understand how I can mock my db with a separate route/controller/dao/app architecture
@JohnWilson-mk2jp
@JohnWilson-mk2jp 2 года назад
Exactly, this seems to only work if all logic; routes, controllers, services/business logic are in one file and Db calls all happen directly inside the createApp function. Would be useful to know how to mock the data access layer for a layered architecture.
@theasker6199
@theasker6199 2 месяца назад
bit of a late reply but if you have separate router files, turn them into static classes that get exported. that way, app.js can send your database into the classes via a static function in each class to get the router and set the database, the classes save them as static properties, and now you got routers in separate files all using the database passed into app.js. Hope that helps.
@saulramirez727
@saulramirez727 2 года назад
Quoting previous comment: great playlists
@carlosdelgado5632
@carlosdelgado5632 3 года назад
Nice how everything was explained and using some tdd for test 💯
@eromengreek
@eromengreek 5 месяцев назад
You are actually testing the API endpoint, not the actual function that creates the user in the database.
@datyapinnamaneni9925
@datyapinnamaneni9925 Год назад
Hallo Sam, Thank you for TDD concept. Can you make error handling in Nodejs in your way
@joelmathew5655
@joelmathew5655 Год назад
Great content. One question though, the object database being passed in a jest instance for unit testing. How do we ensure that, for normal execution, the database object points to the database ? Without changing the business logic code or adding if blocks
@castulo
@castulo Год назад
Great video Sam, keep it up!
@anasaljawa858
@anasaljawa858 3 года назад
Great Content, I love how make it easier to understand
@happy..1907
@happy..1907 3 года назад
Nicely explained. Thanks for creating this.
@sangitsigdel4971
@sangitsigdel4971 3 года назад
Awesome video Sam. Keep Going... Love your teaching style..
@--------------------.
@--------------------. 2 года назад
Amazing, love that content and methodical explanation!
@TheAppAlchemist
@TheAppAlchemist 2 года назад
please upload the next episode
@normandrental2695
@normandrental2695 Год назад
This is awesome! Thank you so much!
@chilly2171
@chilly2171 3 года назад
How does Jest.fn() even know what queries to call when the database.js was not even connected or when not a single database query is written??? 5:09
@jamesdaniels6134
@jamesdaniels6134 2 года назад
It isn't connected to the database. Jest.fn() can 'mock' a database call. For example, if your database query returned `{username: "chilly21"}` when a request was sent to it with `{userId: 1}`, then you could simulate this with Jest.fn(({userId})=> return {username:"chilly21"}). The idea is that you completely remove the connection to your database so that it speeds up your testing and so that your database is preserved. The Jest.fn() function allows you to simulate a database call and also gives you lots of other features, such as allowing you to test number of times called (eg `expect(mockCallback.mock.calls.length).toBe(2);`).
@charbelsarkis3567
@charbelsarkis3567 Год назад
Is it wrong to test the code actually accesses and saves on the database? Like what if I have a flag for testing and it connects to a test database
@eduardocarvalho4232
@eduardocarvalho4232 3 года назад
Thanks men, very good content!
@Opim97
@Opim97 3 года назад
Great content! Really appreciate the effort put into this. I had a question in regards to what the console displays when running the tests, might be something I have to add in a config file. When I'm running my tests, the console outputs "PASS folder/myTestFile.js", but not the describe and test description. Any idea on how to show this output?
@xf2809
@xf2809 5 месяцев назад
how to send the jwt token while login (i am talking about cookies not bearer token ) i stuck here
@blameItleaveit
@blameItleaveit 3 года назад
Great video 👍🏼👍🏼,How we can test if real database throw an error like email is already exist ?
@Italoqo1
@Italoqo1 2 года назад
Awesome, great content!
@zachminner5668
@zachminner5668 2 года назад
Very helpful!
@muhammadjawad2235
@muhammadjawad2235 2 года назад
I love you man. You are awesome
@JPB983
@JPB983 Год назад
great stuff
@fartake
@fartake 2 года назад
great video, helped me a lot :)
@sammygopeh7578
@sammygopeh7578 Год назад
Sam, 🥺 thank you
@SamMeechWard
@SamMeechWard Год назад
You’re welcome 😊
@sandhyalakshmi1697
@sandhyalakshmi1697 10 месяцев назад
Can anyone tell me how to mock transactions?
@DR-ee4wv
@DR-ee4wv 2 года назад
damn good video. I wish I could donate
@schechtere
@schechtere Год назад
Good instruction, but could do without the music -- or at least, turn the level down so it's not louder than the speech.
@SamMeechWard
@SamMeechWard Год назад
I agree, I don't do that anymore
@hoaibao1638
@hoaibao1638 2 года назад
Great video!!! Can I get the song's name pls?
@robwindowski9332
@robwindowski9332 8 месяцев назад
Toby Tranter - Memories Don't Lie
@mcdthedev
@mcdthedev Год назад
great content my guy but you rush so much that its hard to keep up
@shahidabbas2932
@shahidabbas2932 2 года назад
hello sir ...
Далее
Mock vs Spy in Testing with Jest: Which is Better?
25:12
Dependency Injection in JavaScript
9:37
Просмотров 41 тыс.
ДО ВСТРЕЧИ НА РАЗГОНЕ
52:11
Просмотров 438 тыс.
Thoughts About Unit Testing | Prime Reacts
11:21
Просмотров 222 тыс.
Testing Node Server with Jest and Supertest
11:45
Просмотров 117 тыс.
Mocking Asynchronous Functions with Jest
21:50
Просмотров 70 тыс.
Jest. Unit Тестирование в JavaScript
1:27:05
Stop Writing So Many Tests
10:02
Просмотров 88 тыс.
Every Developer Needs a Raspberry Pi
27:27
Просмотров 488 тыс.
The ONLY REASON To Unit Test
8:26
Просмотров 78 тыс.
ДО ВСТРЕЧИ НА РАЗГОНЕ
52:11
Просмотров 438 тыс.