{"id":13725533,"url":"https://github.com/kentcdodds/how-jest-mocking-works","last_synced_at":"2025-04-09T17:25:09.283Z","repository":{"id":48145494,"uuid":"73116550","full_name":"kentcdodds/how-jest-mocking-works","owner":"kentcdodds","description":null,"archived":false,"fork":false,"pushed_at":"2021-01-25T23:14:16.000Z","size":1021,"stargazers_count":311,"open_issues_count":3,"forks_count":32,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-02T11:49:53.035Z","etag":null,"topics":["kcd-edu"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kentcdodds.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-07T20:10:53.000Z","updated_at":"2025-02-11T21:57:34.000Z","dependencies_parsed_at":"2022-09-16T03:20:28.909Z","dependency_job_id":null,"html_url":"https://github.com/kentcdodds/how-jest-mocking-works","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentcdodds%2Fhow-jest-mocking-works","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentcdodds%2Fhow-jest-mocking-works/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentcdodds%2Fhow-jest-mocking-works/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kentcdodds%2Fhow-jest-mocking-works/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kentcdodds","download_url":"https://codeload.github.com/kentcdodds/how-jest-mocking-works/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248075797,"owners_count":21043650,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kcd-edu"],"created_at":"2024-08-03T01:02:26.352Z","updated_at":"2025-04-09T17:25:09.265Z","avatar_url":"https://github.com/kentcdodds.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# How Jest Mocking Works\n\nThis title is a bit misleading. I'm not explaining everything about Jest mocking, just something I wanted to test out\nand thought was kind of interesting. So it turns out that if you make a call to `jest.mock` in the root of your module,\nthat mocking will take place before any require statements are resolved/run. This actually makes Jest's mocking\ncapabilities really powerful! It essentially means that you can import all the stuff you would normally, and not worry\nabout whether you're mocking things in time. Pretty legit!\n\nAnd Christoph [comes in](https://twitter.com/cpojer/status/795729860819820544) to give a little more insight here :)\nLooks like you can use `jest.doMock` or `jest.dontMock` to change this behavior.\n\n![tweets](tweets.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkentcdodds%2Fhow-jest-mocking-works","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkentcdodds%2Fhow-jest-mocking-works","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkentcdodds%2Fhow-jest-mocking-works/lists"}