/
githubmirror
/
jest
Обзор
Документация
Войти
/
githubmirror
/
jest
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/module-mock/__tests__/partial_mock.js
30 строк
905 B
Paul O’Shannessy
Update copyrights with Meta Platforms, restore original license in Jasmine fork (#13879)
09 фев 2023, 10:13
Не верифицирован
09 фев 2023, 10:13
6d2632a
Код
Авторство
О чём код?
// Copyright (c) Meta Platforms, Inc. and affiliates.. All Rights Reserved. /** * This file illustrates how to do a partial mock where a subset * of a module's exports have been mocked and the rest * keep their actual implementation. */ import defaultExport, {apple, strawberry} from '../fruit'; jest.mock('../fruit', () => { const originalModule = jest.requireActual('../fruit'); const mockedModule = jest.createMockFromModule('../fruit'); //Mock the default export and named export 'apple'. return { ...mockedModule, ...originalModule, apple: 'mocked apple', default: jest.fn(() => 'mocked fruit'), }; }); it('does a partial mock', () => { const defaultExportResult = defaultExport(); expect(defaultExportResult).toBe('mocked fruit'); expect(defaultExport).toHaveBeenCalled(); expect(apple).toBe('mocked apple'); expect(strawberry()).toBe('strawberry'); });