Using Jest.Mock() To Mock Modules

TopicSource
๐Ÿงฉ React[React Testing Library and Jest: The Complete Guide

Module mocking allows you to overwrite modules with dummy mocks.

Module mocking describes the process of overwriting some module, that you would normally import into your test. For example, when a component is making trouble during testing due to weird imports, you can decide to exclude it from the test, if you are certain that it shouldn't affect the testing result.

You can then create a mock version of this module, that is imported instead.

jest.mock('../tree/FileIcon', () => {
	return () => {
		return 'File Icon Component' // this replaces the content from '../tree/FileIcon'
	}
});

  1. Module mocking is a bad way to test data fetching