Ручні імітації
Ручні імітації використовуються як заглушки функціоналу імітаціями даних. Наприклад, замість того, щоб отримати доступ до віддаленого ресурсу на зразок вебсайту або бази даних, ви можете створити ручну імітацію, яка дозволить використання фіктивних даних. Це гарантує, що ваші тести будуть швидкими та однорідними.
Імітація модулів користувача
Manual mocks are defined by writing a module in a __mocks__/ subdirectory immediately adjacent to the module. For example, to mock a module called user in the models directory, create a file called user.js and put it in the models/__mocks__ directory.
The __mocks__ folder is case-sensitive, so naming the directory __MOCKS__ will break on some systems.
When we require that module in our tests (meaning we want to use the manual mock instead of the real implementation), explicitly calling jest.mock('./moduleName') is required.