Fix jest mocking in tests (#592)

Summary:
Pull Request resolved: https://github.com/facebook/flipper/pull/592

Finally we can join the 21st century and use `jest.mock` in tests!

I'm enabling the ts-jest transform to `*/__tests__/*.tsx` files. This takes care of transforming the typescript, and preserves jest mock capabilities.
I have left the existing custom transform on all other files, so they will continue to work as usual.

Caveats:
* Our existing custom transforms will no longer be applied in tests.
  * With our current suite this makes no difference. But bear in mind things like importing directly from 'flipper' instead of the actual files, won't work. However, I don't see this being a problem, as I think they'll only be needed inside the actual product code.

Reviewed By: passy

Differential Revision: D17978753

fbshipit-source-id: df7b312b5dd5592e4aa4f8df605f5952ea3158e9
This commit is contained in:
John Knox
2019-10-18 07:16:15 -07:00
committed by Facebook Github Bot
parent cc19cc75ee
commit 781344f7de
6 changed files with 131 additions and 13 deletions

View File

@@ -7,11 +7,17 @@
* @format
*/
jest.mock('../../fb-stubs/Logger');
try {
jest.mock('../../fb/Logger');
} catch {
// Allowed to fail when fb modules are not present.
}
import {default as PluginInstaller, PluginDefinition} from '../PluginInstaller';
import React from 'react';
import {render, waitForElement} from '@testing-library/react';
import {init as initLogger} from '../../fb-stubs/Logger';
import configureStore from 'redux-mock-store';
const mockStore = configureStore([])({application: {sessionId: 'mysession'}});
@@ -31,7 +37,6 @@ const indexMock: algoliasearch.Index = ({
beforeEach(() => {
indexMock.search = jest.fn(async () => SEARCH_RESULTS);
initLogger(mockStore as any, {isTest: true});
});
test('load PluginInstaller list', async () => {