Тёмный

Testing Serverless Functions with Jest & Next.js API Routes 

Colby Fayock
Подписаться 27 тыс.
Просмотров 8 тыс.
50% 1

Learn how to use Jest to test serverless functions using Next.js API routes. We'll walk through spinning up a new demo project to test with, installing and configuring Jest, and writing tests for a serverless function.
Next.js API Route Demo Starter
github.com/colbyfayock/demo-n...
🗒️ Read More
spacejelly.dev/posts/how-to-t...
🎬 Next Up
How to Use Postman to Test APIs and Manage Collections
• How to Use Postman to ...
Visual Regression Testing Tutorial with Applitools Eyes and Cypress
• Visual Regression Test...
How to Use Github Actions to Automate Tests and Slack Notifications
• How to Use Github Acti...
🔔 Subscribe for more tech and developer videos
ru-vid.com?s...
🐦 Get updates straight to your Twitter @colbyfayock
/ colbyfayock
📸 Catch the next stream live on Twitch @colbyfayock
/ colbyfayock
✉️ Or a newsletter right to your inbox!
www.colbyfayock.com/newsletter/
💝 Sponsor me for more free content like this!
GitHub: github.com/sponsors/colbyfayock
Other: hello@colbyfayock.com
👨‍🚀 Brought to by colbyfayock.com
www.colbyfayock.com
🎥 Want to know what A/V equipment I use?
www.colbyfayock.com/what-i-use
🧰 More Resources
Next.js API Route Demo Starter
github.com/colbyfayock/demo-n...
Next.js API Routes
nextjs.org/docs/api-routes/in...
Jest
jestjs.io/
@babel/plugin-transform-modules-commonjs
babeljs.io/docs/en/babel-plug...
🎼 Music
Music from Uppbeat (free for Creators!):
uppbeat.io/t/mountaineer/balcony
License code: BVUDPXZUFNDGNZ0H
#colbyfayock #jest #nextjs #testautomation #serverless #apis #webdevelopment

Наука

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

 

19 авг 2021

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 38   
@colbyfayock
@colbyfayock Год назад
Get fresh tutorials and other free content straight to your inbox! colbyfayock.com/news
@jasonden1005
@jasonden1005 2 года назад
Thank you for walking through and making the points easy to understand. It’s enjoyable.
@colbyfayock
@colbyfayock 2 года назад
glad it was able to help!
@roymathew7956
@roymathew7956 6 месяцев назад
Thank you Colby for your very clear articulation. I was struggling with understanding why I was getting the error you covered here.
@colbyfayock
@colbyfayock 6 месяцев назад
glad it was able to help!
@c4346
@c4346 2 года назад
very interesting, thank you for this tutorial
@colbyfayock
@colbyfayock 2 года назад
No problem 😁
@ARSHADKHAN-hc6pb
@ARSHADKHAN-hc6pb 2 года назад
Great video 👍
@colbyfayock
@colbyfayock 2 года назад
Thank you! 🙏
@darkfoxwillie
@darkfoxwillie 2 года назад
thanks for posting the code :)
@colbyfayock
@colbyfayock 2 года назад
No problem!
@andrewiglinski148
@andrewiglinski148 11 месяцев назад
Aw dude I'd kiss you right now if you were here... When I first became a pretty capable dev I asked this senior dude at a massive company by me what's the best advice he had for someone trying to become a senior dev. He told me testing and GraphQL (this was a while ago). I mastered GraphQL that weekend and since then I've became pretty capable with a couple more languages... and I've still never written a single test.
@colbyfayock
@colbyfayock 11 месяцев назад
haha yeah, tests are one of those things where you don't need it until you really need it, and by then it might be too late. it's a good habit to get into but its not something id fall on my sword for. priorities are important to consider and the level of impact particular pieces have. if im writing logic that handles everything for taking people's money in an online store, id likely wanna have tests of that. if i'm building mission-critical UI for scientists or people saving other's lives, id probably wanna have tests for that. if im building a notetaking app and trying to scale it fast, meh, those could probably wait, but thats a tradeoff risk anyways glad this video helped :)
@JamesQQuick
@JamesQQuick 2 года назад
Awesome!,
@colbyfayock
@colbyfayock 2 года назад
thank you!!!
@paradise5534
@paradise5534 2 месяца назад
ur the goat!
@colbyfayock
@colbyfayock 2 месяца назад
🙏
@chrisl2773
@chrisl2773 Год назад
This is useful and all, but how would you go about testing for calls to a database? For example, I have a Postgres Database that my Next.JS' backend will need to make a call to? I've been trying to get it to work with a multitude of different packages but still not finding any success
@colbyfayock
@colbyfayock Год назад
typically you woudl "mock" those requests so that you're not actually making real requests / mutations to the database. for instance: jestjs.io/docs/mock-functions#mocking-modules
@chrisl2773
@chrisl2773 Год назад
@@colbyfayock I see, I'll give it a look, thank you for the response! :D
@deepakn8581
@deepakn8581 2 года назад
When I import the handler file and console log for me that's showing undefined instead of handler function.
@colbyfayock
@colbyfayock 2 года назад
hey not sure about this one, the handler is just an export javascript module so there shouldnt be anything special going on. here's my code github.com/colbyfayock/my-next-jest
@josemfcheo
@josemfcheo 2 года назад
Bro, I love you...
@colbyfayock
@colbyfayock 2 года назад
♥️
@jerbparagas3924
@jerbparagas3924 6 месяцев назад
Can you do Next14 version REST API route test tutorial with jest?
@colbyfayock
@colbyfayock 6 месяцев назад
just to clarify what you're looking for, basically this same video but for the App router? are you stuck with Jest? I likely would do a newer video with vitest, though i would expect for the most part there should be enough similarities to follow along
@jerbparagas3924
@jerbparagas3924 6 месяцев назад
@@colbyfayock Yes, app router, I'm new to testing but I would like to start testing rest api endpoints. What can you recommend for a beginner, vitest or jest?
@colbyfayock
@colbyfayock 6 месяцев назад
@@jerbparagas3924the community seems to be largely pooling support around vitest, i think it is a great option. this video and all tests ive run so far in Jest pretty much "just work" with vitest "as is" with the exception of just needing to import some of the functions that jest would auto include, if that makes sense check this out: vitest.dev/guide/ but seems like i need to make a vitest video generally
@27sosite73
@27sosite73 7 месяцев назад
damn is it me or this is only one video on this topic in the hole youTube?
@colbyfayock
@colbyfayock 7 месяцев назад
👀 glad i was able to help
@blahblah-rn1ts
@blahblah-rn1ts 2 года назад
why were those serverless functions?
@colbyfayock
@colbyfayock 2 года назад
can you elaborate? do you mean as opposed to running it on a traditional server?
@blahblah-rn1ts
@blahblah-rn1ts 2 года назад
@@colbyfayock A function is not intrinsically serverless. It becomes serveless by way of deployment and execution. At the moment of you testing it it's just a function.
@colbyfayock
@colbyfayock 2 года назад
@@blahblah-rn1ts thanks for the heads up!
@blahblah-rn1ts
@blahblah-rn1ts 2 года назад
@@colbyfayock The content of the video was great, though. Thank you for that. Would also love to see something more close to reality where you'd had to deal with database layer. (e.g. via Prisma)
@RdozeTV
@RdozeTV 2 года назад
I hate that kind of tutorial. Can you make real tutorial, complex application and not a calculator test
@colbyfayock
@colbyfayock 2 года назад
thanks for the feedback
@Hyokora
@Hyokora Год назад
tf
Далее
Build a Notification System in Next.js with Knock
57:50
iPhone, Galaxy или Pixel? 😎
0:16
Просмотров 430 тыс.
АЙФОН Г0ВН0
0:54
Просмотров 245 тыс.