Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ const projects = [
transform: {
//'^.+\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js', //setup.js needs to be transformed, but preprocessor screws everything else up
...baseConfig.transform,
'^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve(
'react-native/jest/assetFileTransformer.js',
), //from RN preset
'^.+\\.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$':
require.resolve('react-native/jest/assetFileTransformer.js'), //from RN preset
},
haste: {
//from RN preset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ const TestComponent = () => {

// Test cases
describe('Integration Garbage Collection React Native', () => {
let warnSpy: jest.SpyInstance;
let errorSpy: jest.SpyInstance;
beforeAll(() => {
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});
afterAll(() => {
warnSpy.mockRestore();
errorSpy.mockRestore();
});

it('should count properly with useSuspense', async () => {
jest.useFakeTimers();

Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/__tests__/integration.node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import { payload } from '../test-fixtures';

describe('SSR', () => {
let renderDataClient: ReturnType<typeof makeRenderDataClient>;
let errorSpy: jest.SpyInstance;
beforeAll(() => {
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});
afterAll(() => {
errorSpy.mockRestore();
});

beforeEach(() => {
renderDataClient = makeRenderDataClient(ExternalDataProvider);
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/__tests__/optional-members.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ const fixture: FixtureEndpoint = {

describe(`optional members`, () => {
let renderDataClient: ReturnType<typeof makeRenderDataClient>;
let errorSpy: jest.SpyInstance;
beforeAll(() => {
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});
afterAll(() => {
errorSpy.mockRestore();
});

beforeEach(() => {
renderDataClient = makeRenderDataClient(CacheProvider);
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/__tests__/subscriptions-endpoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ describe.each([
function onError(e: any) {
e.preventDefault();
}
let infoSpy: jest.SpyInstance;
let errorSpy: jest.SpyInstance;
beforeAll(() => {
infoSpy = jest.spyOn(console, 'info').mockImplementation(() => {});
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});
afterAll(() => {
infoSpy.mockRestore();
errorSpy.mockRestore();
});
beforeEach(() => {
if (typeof addEventListener === 'function')
addEventListener('error', onError);
Expand Down
10 changes: 7 additions & 3 deletions packages/react/src/components/__tests__/AsyncBoundary.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ describe('<AsyncBoundary />', () => {
function onError(e: any) {
e.preventDefault();
}
let errorSpy: jest.SpyInstance;
beforeAll(() => {
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});
afterAll(() => {
errorSpy.mockRestore();
});
beforeEach(() => {
if (typeof addEventListener === 'function')
addEventListener('error', onError);
Expand Down Expand Up @@ -45,8 +52,6 @@ describe('<AsyncBoundary />', () => {
expect(getByText(/loading/i)).not.toBeNull();
});
it('should catch non-network errors', () => {
const originalError = console.error;
console.error = jest.fn();
let renderCount = 0;
function Throw(): ReactElement {
renderCount++;
Expand All @@ -60,7 +65,6 @@ describe('<AsyncBoundary />', () => {
);
const { getByText, queryByText, container } = render(tree);
expect(getByText(/you failed/i)).not.toBeNull();
console.error = originalError;
expect(renderCount).toBeLessThan(10);
});
it('should render error case when thrown', () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/react/src/components/__tests__/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import DataProvider from '../DataProvider';
import { getDefaultManagers } from '../getDefaultManagers';

describe('<DataProvider />', () => {
let errorSpy: jest.SpyInstance;
beforeAll(() => {
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});
afterAll(() => {
errorSpy.mockRestore();
});

let warnspy: jest.Spied<any>;
let debugspy: jest.Spied<any>;
beforeEach(() => {
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/hooks/__tests__/subscriptions.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ describe.each([
tags: ['a', 'best', 'react'],
};
let renderDataClient: ReturnType<typeof makeRenderDataClient>;
let infoSpy: jest.SpyInstance;
let errorSpy: jest.SpyInstance;
beforeAll(() => {
infoSpy = jest.spyOn(console, 'info').mockImplementation(() => {});
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});
afterAll(() => {
infoSpy.mockRestore();
errorSpy.mockRestore();
});
async function validateSubscription(
result: {
readonly current: Article | undefined;
Expand Down
10 changes: 10 additions & 0 deletions packages/react/src/hooks/__tests__/subscriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ describe.each([
tags: ['a', 'best', 'react'],
};
let renderDataClient: ReturnType<typeof makeRenderDataClient>;
let infoSpy: jest.SpyInstance;
let errorSpy: jest.SpyInstance;
beforeAll(() => {
infoSpy = jest.spyOn(console, 'info').mockImplementation(() => {});
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});
afterAll(() => {
infoSpy.mockRestore();
errorSpy.mockRestore();
});
async function validateSubscription(
result: {
readonly current: Article | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ export const nested: FixtureEndpoint = {
let renderDataClient: ReturnType<typeof makeRenderDataClient>;
let mynock: nock.Scope;

let errorSpy: jest.SpyInstance;
beforeAll(() => {
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
});
afterAll(() => {
errorSpy.mockRestore();
});
beforeEach(() => {
renderDataClient = makeRenderDataClient(CacheProvider);
mynock = nock(/.*/).defaultReplyHeaders({
Expand Down
21 changes: 18 additions & 3 deletions packages/react/src/hooks/__tests__/useController/reset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ describe('resetEntireStore', () => {
});

describe('integration', () => {
let infoSpy: jest.SpyInstance;
beforeAll(() => {
infoSpy = jest.spyOn(console, 'info').mockImplementation(() => {});
});
afterAll(() => {
infoSpy.mockRestore();
});
beforeEach(() => {
renderDataClient = makeRenderDataClient(CacheProvider);
});
Expand All @@ -115,7 +122,9 @@ describe('resetEntireStore', () => {
* this only triggers after commit of reset action so users have a chance to unmount those components if they are no longer relevant (like doing a url redirect from an unauthorized page)
*/
it('should refetch useSuspense() after reset', async () => {
const consoleSpy = jest.spyOn(console, 'error');
const consoleSpy = jest
.spyOn(console, 'error')
.mockImplementation(() => {});

mynock
.get(`/article-cooler/${9999}`)
Expand Down Expand Up @@ -144,14 +153,17 @@ describe('resetEntireStore', () => {

// ensure it doesn't try to setstate during render (dispatching during fetch - which is called from memo)
expect(consoleSpy.mock.calls.length).toBeLessThan(1);
consoleSpy.mockRestore();
});

/**
* upon reset, all inflight requests will not dispatch sets
* promises still reject so external listeners know (abort signals do this as well)
*/
it('should not set fetches that started before RESET', async () => {
const consoleSpy = jest.spyOn(console, 'log');
const consoleSpy = jest
.spyOn(console, 'log')
.mockImplementation(() => {});
const detail: FixtureEndpoint = {
endpoint: CoolerArticleDetail,
args: [{ id: 9999 }],
Expand Down Expand Up @@ -221,14 +233,17 @@ describe('resetEntireStore', () => {
});

//expect(result.current.resolved).toBe(undefined);
const consoleSpy = jest.spyOn(console, 'error');
const consoleSpy = jest
.spyOn(console, 'error')
.mockImplementation(() => {});
act(() => unmount());

// TODO: Figure out a way to wait until fetch chain resolution instead of waiting on time
await act(() => new Promise(resolve => setTimeout(resolve, 20)));

// when trying to dispatch on unmounted this will trigger console errors
expect(consoleSpy.mock.calls.length).toBeLessThan(1);
consoleSpy.mockRestore();
});
});
});
3 changes: 3 additions & 0 deletions packages/react/src/hooks/__tests__/useDLE.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@ afterAll(() => {

describe('useDLE', () => {
let renderDataClient: ReturnType<typeof makeRenderDataClient>;
let warnSpy: jest.SpyInstance;
beforeEach(() => {
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
mynock.get(`/article-cooler/${payload.id}`).reply(200, payload);
mynock.get(`/article-static/${payload.id}`).reply(200, payload);
mynock.get(`/user/`).reply(200, users);
renderDataClient = makeRenderDataClient(CacheProvider);
});
afterEach(() => {
warnSpy.mockRestore();
renderDataClient.cleanup();
nock.cleanAll();
});
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/hooks/__tests__/useFetch.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,16 @@ afterAll(() => {

describe('useFetch', () => {
let renderDataClient: ReturnType<typeof makeRenderDataClient>;
let warnSpy: jest.SpyInstance;
beforeEach(() => {
warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
mynock.get(`/article-cooler/${payload.id}`).reply(200, payload);
mynock.get(`/article-static/${payload.id}`).reply(200, payload);
mynock.get(`/user/`).reply(200, users);
renderDataClient = makeRenderDataClient(CacheProvider);
});
afterEach(() => {
warnSpy.mockRestore();
renderDataClient.cleanup();
nock.cleanAll();
});
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/hooks/__tests__/useLive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ describe.each([
tags: ['a', 'best', 'react'],
};
let renderDataClient: ReturnType<typeof makeRenderDataClient>;
let infoSpy: jest.SpyInstance;
beforeAll(() => {
infoSpy = jest.spyOn(console, 'info').mockImplementation(() => {});
});
afterAll(() => {
infoSpy.mockRestore();
});
async function validateSubscription(
result: {
readonly current: Article | undefined;
Expand Down
Loading