Next.js with React Testing Library, Jest, TypeScript

Next.js with React Testing Library, Jest, TypeScript

Dave Gray

9 месяцев назад

50,718 Просмотров

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


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

@dazecm
@dazecm - 27.11.2023 17:58

Thanks for this Dave. The Using App Router docs at Vercel still do not have specific Testing documentation in the Optimizing section as of Next version 14.0.3 and I was struggling getting Jest and React Testing Library configured properly.

Ответить
@Sidgd1987
@Sidgd1987 - 16.11.2023 17:40

Why do we have jest.setup.js?

Ответить
@ricardorien
@ricardorien - 07.11.2023 20:30

Works fine with Next 14.0.1. just nuke yarn-error, yarn.lock and node-modules/ and install everything again before run 'yarn jest'.

Ответить
@JosephGoebbelcoque
@JosephGoebbelcoque - 27.10.2023 07:47

Replace jest.setup.js with the line "import '@testing-library/jest-dom'" because extend-expect is not there anymore

Ответить
@seanfang398
@seanfang398 - 27.10.2023 01:18

Oh, thank you so much! Really saved my day❤ I don't know about others, but for me, working with typescript sometimes can be very head-scratching and I myself fell into quite a few traps😂 And contents like setting configs or some other little tricks can be very very helpful, just like what this video demonstrates. Thank you again and hopefully we could watch more great video in this channel

Ответить
@kikaccc93
@kikaccc93 - 25.10.2023 13:49

It would be nice to see some unit testing in react native using react native library and jest.Also love your explanations.

Ответить
@MicroUrb
@MicroUrb - 23.10.2023 20:24

I am curious, why is your test extension `tsx` as opposed to just `ts`? Is it because you did not create it as a spec file?

Ответить
@malakggh
@malakggh - 21.10.2023 23:56

npm i -D @testing-library/[email protected] @testing-library/react @testing-library/user-event jest jest-environment-jsdom ts-jest

Ответить
@nan-simon
@nan-simon - 13.10.2023 14:27

You are the best!!! Thank you! 😍😍😍

Ответить
@benallan5078
@benallan5078 - 04.10.2023 19:06

Hey Dave! I'd love some react testing videos. Finding resources to effectively explain testing react hooks and redux usages are few and far between!

Ответить
@michalnowak2181
@michalnowak2181 - 03.10.2023 21:15

thx

Ответить
@gopinathmano7910
@gopinathmano7910 - 03.10.2023 18:00

yes sir we need react testing video

Ответить
@1DanielQ7
@1DanielQ7 - 03.10.2023 16:15

How comes you are using extend-expect when it was removed in @testing-library/jest-dom v6.0?

Ответить
@romero-r
@romero-r - 26.09.2023 23:26

I've been fighting jest, typescript, webpack, nextjs, and vite the whole day trying to set up a test runner for a nextjs project created with create-t3-app. The pain in the js ecosystem is real. I hope I can just use bun for everything soon.
Anyways, this video got me the closest to a perfect setup just a tiny bit of googling aside from the instructions in this video got jest+RTL working! Thank you!

Ответить
@o12345684
@o12345684 - 22.09.2023 02:37

That rolling back for @testing-library/[email protected] saved me hours of searching. Thanks a lot

Ответить
@JayFFresh
@JayFFresh - 19.09.2023 22:41

not gonna lie, all the switching from versions makes everything so uncertain

Ответить
@mmtt1129
@mmtt1129 - 09.09.2023 05:10

I encountered the error " ReferenceError: Can't find variable: document
at render ....". I already set testEnvironment: "jest-environment-jsdom". Anybody can help me ? Thanks

Ответить
@user-eb3cg3lo1t
@user-eb3cg3lo1t - 04.09.2023 14:32

__tests__/productImages.test.tsx
● Test suite failed to run

Cannot find module '@testing-library/jest-dom/extend-except' from 'jest.setup.js'
please help

Ответить
@htmlfivedev
@htmlfivedev - 03.09.2023 08:17

I was really glad to find this video but when I went through it, I realized things are just too problematic to even set up Jest with the Next 13 right now ... conflict after conflict ... will get back when the issues are resolved ...

Ответить
@jazzdestructor
@jazzdestructor - 02.09.2023 17:13

HI Dave, thanks a lot for the jest video as you asked Could you Please do react vite vitest video on a big react project?? like the blog project you had in your redux video?? want to see how it works compared to jest and learn more on how it does crud on frontend?

Ответить
@noNullMoments
@noNullMoments - 02.09.2023 15:27

codium tutorials please. thats a great tool n ure a great teacher. win || win

Ответить
@focusme-tv3650
@focusme-tv3650 - 31.08.2023 17:20

Hello! This is a very nice video for beginners learning about the basics of testing. I came here with a bit more experience and I can't even get one test passing since next 13. The useRouter hook just keeps throwing the same error: " invariant expected app router to be mounted". If you don't have an idea yet about your next video, showing how to setup the tests when using "next/navigation" package should be a good one, not "next/router" (this is important) 👌Thanks for the content

Ответить
@emmanuelumeh8053
@emmanuelumeh8053 - 30.08.2023 23:45

Incase anyone is getting this annoying error.

Details:

/<path>/node_modules/uuid/dist/esm-browser/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { default as v1 } from './v1.js';


Just add this to your jest.config file

....

moduleNameMapper: {
"^uuid$": "uuid"
}

Full code would look like

// Add any custom config to be passed to Jest
/** @type {import('jest').Config} */
const config = {
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],

testEnvironment: 'jest-environment-jsdom',
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
preset: 'ts-jest',
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'],
transformIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/cypress/'],
moduleNameMapper: {
"^uuid$": "uuid"
}
}

Ответить
@27sosite73
@27sosite73 - 30.08.2023 00:53

damn next.js with this versions and all that libraries
struggled a lot

thank you mate <3

Ответить
@gorkemka4061
@gorkemka4061 - 26.08.2023 17:47

thank you!

Ответить
@darawan_omar
@darawan_omar - 25.08.2023 23:33

Mr Dave Can You Give The Effect Filter Of Your OBS

Ответить
@ryanwoods3333
@ryanwoods3333 - 25.08.2023 21:11

Thank you! I really hope you produce more unit-testing videos with React!

Ответить
@bhasker8789
@bhasker8789 - 25.08.2023 08:05

Sir please make videos django course from beginniner to advance.

Ответить
@hamza-alrashed
@hamza-alrashed - 22.08.2023 09:04

Hi Dave .. Thank you so much about everything .. I learned from you alot of things not just programming .. I learned from you english language also Your accent very clear .. I have one request please .. Can you start with SQL I need this for my work and I need to understand it using your explanation

Thanks
Hamza

Ответить
@syedsadiq8591
@syedsadiq8591 - 22.08.2023 06:42

Great! Waiting for next video.

Ответить
@nanonkay5669
@nanonkay5669 - 21.08.2023 01:21

Bruh half the video was just setup and configurations. This is why no one likes to do testing 😂

Ответить
@khamzateedira9021
@khamzateedira9021 - 20.08.2023 17:29

Can you do it more testing with react❤❤❤

Ответить
@farahrayis5928
@farahrayis5928 - 20.08.2023 15:01

Looking forward to more videos on testing, thanks Dave.

Ответить
@Nanashi-rq7lk
@Nanashi-rq7lk - 20.08.2023 05:56

Nice tutorial,Thanks

Ответить
@AirOfFreshBlue
@AirOfFreshBlue - 19.08.2023 21:59

dear dave, why in nextjs 13.4 app directory we have several errors for testing aplication?

Ответить
@yourcasualdeveloper
@yourcasualdeveloper - 19.08.2023 21:27

Yet another great video.

Ответить
@bewildstudio
@bewildstudio - 19.08.2023 17:51

Please, please... make a video about How to test React) you are a great teacher... do you work offline as a teacher?)

Ответить
@nishant810125
@nishant810125 - 19.08.2023 17:11

Hey Dave! You've are a saviour/ultimate mentor for those who are diving deep into Next.js. Appreciate your progressive content. Thank you.

Ответить
@JustAPoorDevleoper409
@JustAPoorDevleoper409 - 19.08.2023 14:25

Thanks for this awesome video
i was struggling to understand testing with nextjs ❤

Ответить
@viniciusmassari5503
@viniciusmassari5503 - 19.08.2023 13:46

Hey Dave ! any thoughts about a testing course ? Like, what is mock, spy, stub, e2e and unit testing...Maybe a little teoric and practice introduction to these subjects, as a beginner I feel that will be a great adittion to my studies, recently I came across many videos about that.

Thank you for your teachings ! Helped me a lot to learn Nextjs

Ответить
@danieljing9319
@danieljing9319 - 19.08.2023 07:02

This is what we want !!!! Dave you are my hero! You always provide useful and advanced stuff !!! 👍👍

Ответить
@farazk9729
@farazk9729 - 19.08.2023 06:34

Hi Dave,

I am doing some of your other videos, and a little something I wanted to thank you for: Thanks for explaining the little things that you do and not just doing them (e.g. Ctrl + B to hide the file tree, etc etc). These tidbits make the learning journey more fun, clearer, and basically make me feel more involved in what's happening, which makes me want to keep at it, so muchas gracias ;-)

Ответить
@okbaalla8451
@okbaalla8451 - 19.08.2023 01:58

Finally, we need more of this Dave, keep it up, I want to question you about two things:

The vscode extension you're using for the icons

When selecting the pages and not the app features in next project inititializing, will it work with same new SSR and SSG functionalities or we will use the getStaticProps, getServerSideProps keywords, thanks!

Ответить
@yonnierenton6177
@yonnierenton6177 - 19.08.2023 01:17

Super Love it thankyou! I used Chai with Hardhat. Yeeew lol...

Ответить
@hydrohelp9847
@hydrohelp9847 - 18.08.2023 21:10

Awesome stuff man

Ответить
@sadeshure5241
@sadeshure5241 - 18.08.2023 21:08

Ever thought of adding React native (mobile) tuts to your channel Dave?

Ответить
@AshishKumar-du2wk
@AshishKumar-du2wk - 18.08.2023 20:46

Hey Dave can you teach us auth0 for next js 13 ?

Ответить
@waleedsharif618
@waleedsharif618 - 18.08.2023 20:43

I wonder why Nextjs does not come with testing like create react app comes… it would help a lot

Ответить
@emobodigo
@emobodigo - 18.08.2023 20:38

Thank you dave, i hope you will continue this testing video as series, it will help so much❤

Ответить