Skip to content

Commit aa3dc1c

Browse files
author
ismay
committed
fix(logging): silence react-query logger by default
1 parent db00a91 commit aa3dc1c

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

services/data/src/__tests__/integration.test.tsx

-15
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
import { render, waitFor } from '@testing-library/react'
22
import React, { ReactNode } from 'react'
3-
import { setLogger } from 'react-query'
43
import { CustomDataProvider, DataQuery } from '../react'
54
import { QueryRenderInput } from '../types'
65

7-
beforeAll(() => {
8-
// Prevent the react-query logger from logging to the console
9-
setLogger({
10-
log: jest.fn(),
11-
warn: jest.fn(),
12-
error: jest.fn(),
13-
})
14-
})
15-
16-
afterAll(() => {
17-
// Restore the original react-query logger
18-
setLogger(console)
19-
})
20-
216
describe('Testing custom data provider and useQuery hook', () => {
227
it('Should render without failing', async () => {
238
const data = {

services/data/src/react/hooks/useDataQuery.test.tsx

-15
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
11
import { renderHook, act } from '@testing-library/react-hooks'
22
import React from 'react'
3-
import { setLogger } from 'react-query'
43
import { CustomDataProvider } from '../components/CustomDataProvider'
54
import { useDataQuery } from './useDataQuery'
65

7-
beforeAll(() => {
8-
// Prevent the react-query logger from logging to the console
9-
setLogger({
10-
log: jest.fn(),
11-
warn: jest.fn(),
12-
error: jest.fn(),
13-
})
14-
})
15-
16-
afterAll(() => {
17-
// Restore the original react-query logger
18-
setLogger(console)
19-
})
20-
216
describe('useDataQuery', () => {
227
describe('parameters: onComplete', () => {
238
it('Should call onComplete with the data after a successful fetch', async () => {

services/data/src/react/hooks/useDataQuery.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
import { useState, useRef } from 'react'
2-
import { useQuery } from 'react-query'
2+
import { useQuery, setLogger } from 'react-query'
33
import { Query, QueryOptions } from '../../engine'
44
import { FetchError } from '../../engine/types/FetchError'
55
import { QueryRenderInput, QueryRefetchFunction } from '../../types'
66
import { useDataEngine } from './useDataEngine'
77
import { useStaticInput } from './useStaticInput'
88

9+
const noop = () => {
10+
/**
11+
* Used to silence the default react-query logger. Eventually we
12+
* could expose the setLogger functionality and remove the call
13+
* to setLogger here.
14+
*/
15+
}
16+
17+
setLogger({
18+
log: noop,
19+
warn: noop,
20+
error: noop,
21+
})
22+
923
export const useDataQuery = (
1024
query: Query,
1125
{

0 commit comments

Comments
 (0)