Thanks for the video Leigh, very helpful For anyone having issues where it returns undefined, I solved it by putting the 'global.fetch....' INSIDE the 'it' function (or in a beforeEach)
@leighhalliday3 жыл бұрын
Thanks Andrew! Thanks for sharing how you solved the issue!
@harikrishnavholla50362 жыл бұрын
Thank you
@jesusgodinho34783 жыл бұрын
Not all heroes wear capes, quite literally. I've been looking to carry out the exact same tests for my API. True legend !
@leighhalliday3 жыл бұрын
Haha thanks! Check out my video on mock service worker, you’re going to love it!
@eestiprogrammeerija12442 жыл бұрын
THANK YOU SO MUCH MAN, you save a lot of time for me, i was googling this for 2 days with no certain answer, thanks
@dawid_dahl4 жыл бұрын
Finally a good testing tutorial! Thank you!
@leighhalliday4 жыл бұрын
Hey Dawid! Check out the video I just published about Mock Service Worker, I think you'll like it!
@MrVisheshsingh4 жыл бұрын
Thank you! Keeping my 👀 open for the upcoming videos
@leighhalliday4 жыл бұрын
Coming tomorrow and Sunday :)
@abessesmahi48884 жыл бұрын
I'am so excited to see the upcoming videos on testing Thank so much sir.
@leighhalliday4 жыл бұрын
Thanks Abesse! One today another tomorrow! :)
@TheDoctorVideos4 жыл бұрын
Great video, really helped me understand how the global fetch and mocking works!
@leighhalliday4 жыл бұрын
Awesome!! Happy it helped :)
@takeshikriang3 жыл бұрын
This is really good Leigh. Thanks for sharing.
@pravinpoudel13073 жыл бұрын
Hello Leight on API request, i get error response of 'You have not supplied an API Access Key. [Required format: access_key=YOUR_ACCESS_KEY]' , is it just me or there is another way to access the API?
@nikosspiropoulos84172 жыл бұрын
the global function fetch now returns undefined when i assing jest.fn to the global object. ANY IDEAS/??????? thanks in advance
@dominikseljan30434 жыл бұрын
Great one Leigh! Can't wait to see other two videos.
@leighhalliday4 жыл бұрын
Thanks Dominik!! One today another tomorrow :)
@umhurram2 жыл бұрын
Thanks Leigh!
@ArtiomNeganov2 жыл бұрын
Very clear explanation. Thank you!
@nicholassmith64122 жыл бұрын
Excellent video
@ibadshaikh22152 жыл бұрын
How to make sure that the fields coming from API response always remain unchanged. Like if the returned object is { rates : {} } , how can I know that the rates key is always there.
@Ls-xb2bn Жыл бұрын
Ur a god. Thanks!!!! Really thanks. This was so usefull
@average-user93 жыл бұрын
thanks! and, it would be cool to have a link to second video in the end, and so on) thanks anyway)
@ahmedjumaah97273 жыл бұрын
Hi Leigh, what if we have a react useState and want to pass the response to the state, how would we test this scenario ? Thanks
@MageLink Жыл бұрын
Dude, you rocks
@larube4 жыл бұрын
Another good video !
@leighhalliday4 жыл бұрын
Thank you Amador :D I appreciate the support!
@larube4 жыл бұрын
@@leighhalliday You deserve it !
@MohieddineSaadeh2 жыл бұрын
Thanks for the video.. I followed the steps but funny enough reject failed my test even if I remove all expects.. Also I'm using NextJS and showing an error message on the screen which is not showing.. I know it is async to begin with, but I did await fetch in my code so basically the rendered HTML should have updated.. Anyways will dig into that.. Thought of sharing my experience.
@sushmak31103 жыл бұрын
Hi Leigh, could you please guide how to mock sequalize ORM on sqlite db
@leighhalliday3 жыл бұрын
Hey Sushma! Perhaps :D If it's something I run into in my development, I'll definitely do one.
@davidobodo36052 жыл бұрын
thanks a lot for this
@akamfoad4 жыл бұрын
thanks great video Leigh, but something is weird, global overriding don't work in my project when doing them outside it/test blocks, made with CRA as well as yours, I saw other projects also using global overriding outside it/test blocks and works well, it seems you guys tweaked something or what is wrong if not?
@leighhalliday4 жыл бұрын
Hey Akam! Sorry... I am not really sure! Perhaps something has changed since the time this video was released... I believe I link to the source code... can you find anything there that might be why?
@stevereid6364 жыл бұрын
I tried following using typescript. I used this: const globalAny: any = global; globalAny.fetch = jest.fn(() => Promise.resolve({ json: () => Promise.resolve({ rates: { CAD: 1.42 } }) }) ); and it worked fine for a time, but when I got to the mockImplementationOnce() , typescript complained that "Property 'mockImplementationOnce' does not exist on type '(input: RequestInfo, init?: RequestInit | undefined) => Promise'." Any ideas on how to resolve this?
@leighhalliday4 жыл бұрын
Hey Steve! Sorry, I am not great with TypeScript... I personally don't know how, but maybe someone else does here? Maybe you can redefine the type of fetch to be a union of whatever type fetch normally has combined with the type of a fetch mock function?
@stevereid6364 жыл бұрын
@@leighhalliday Thanks for the suggestion anyway 👍🏾
@bindushree10373 жыл бұрын
Can you make a video on how to mock the post fetch request which connected to backend having url like localhost:8080 using jest
@leighhalliday2 жыл бұрын
Hey! I would check out "mock service worker" for this sorta thing.
@alanthomasgramont4 жыл бұрын
How do I mock a "service" which isn't using fetch? That service could just be a function call that is may be doing all sorts of things I don't want to test here. import { computeData } from '../services/DataService' I want to replace computeData for all my tests within the component that I'm testing. So my component is calling something like: useEffect(() => { setData(computerData(props.a, props.b)); },[props.a, props.b]) and when data is set, it renders a table or something. computerData isn't a math function or anything and every test might need a different computed result so I don't want to use __Mock__
@leighhalliday4 жыл бұрын
Hey Alan! I would use a manual jest mock but then you can override it with jestjs.io/docs/en/mock-function-api#mockfnmockimplementationoncefn whenever you need it to do something specific for a single test.
@bscodev3 жыл бұрын
Thanks Master!
@chetanjain46163 жыл бұрын
Hey, sorry but I still don't get it, you are still fetching the API right? when , on line number 10, you call convert function it still fetches the API and return the results which lets say if I turn off my internet would result in a failed test right?
@nimatsergiu29424 жыл бұрын
Thanks man this really helped me out ;)
@leighhalliday4 жыл бұрын
Glad I could help, Nimat! Thank you!
@ImranKhansilvake4 жыл бұрын
soo good. thankyou very much
@leighhalliday4 жыл бұрын
Thanks Imran! I appreciate it!
@SheryarShirazi4 жыл бұрын
I'm not getting intellisense like it/test in VSCode react anyone knows?
@leighhalliday4 жыл бұрын
Hmmm... sorry, I'm not sure Sheryar!
@bigk90003 жыл бұрын
Okay, no matter what I do, no matter which method I employ or what package I install, I cannot mock fetch. For whatever the reason, it's utterly impossible.
@leighhalliday3 жыл бұрын
Hey King! Give this a try... it's my preferred way to do it now: kzbin.info/www/bejne/rGial52hgLaHfpI
@rajat4204204 жыл бұрын
How to mock superagent?
@leighhalliday4 жыл бұрын
Hey Rajat! I think you could probably use the approach in this video which is less about mocking and more about intercepting HTTP requests, which would work for fetch/axios/superagent/etc... kzbin.info/www/bejne/rGial52hgLaHfpI
@DarrylHebbes4 жыл бұрын
part time forex trader?
@leighhalliday4 жыл бұрын
Hehe nah, it's just hard to find a simple API to use in examples that doesn't require an API key :D