Skip to content

Commit

Permalink
add (currently failing) RTKQ test
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 committed May 2, 2024
1 parent 13be620 commit e268789
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/toolkit/src/query/tests/matchers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
hookWaitFor,
setupApiStore,
} from '@internal/tests/utils/helpers'
import type { UnknownAction } from '@reduxjs/toolkit'
import { createSlice } from '@reduxjs/toolkit'
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
import { act, renderHook } from '@testing-library/react'
Expand Down Expand Up @@ -239,3 +240,34 @@ test('inferred types', () => {
},
})
})

describe('errors in reducers are not swallowed', () => {
const faultyStoreFor = (matcher: (action: UnknownAction) => boolean) =>
setupApiStore(api, {
...actionsReducer,
faultyReducer(state = null, action: UnknownAction) {
if (matcher(action)) {
throw new Error('reducer error')
}
return state
},
})
test('pending action reducer errors should be thrown', async () => {
const storeRef = faultyStoreFor(api.endpoints.querySuccess.matchPending)
await expect(
storeRef.store.dispatch(querySuccess2.initiate({} as any)),
).rejects.toThrow('reducer error')
})
test('fulfilled action reducer errors should be thrown', async () => {
const storeRef = faultyStoreFor(api.endpoints.querySuccess.matchFulfilled)
await expect(
storeRef.store.dispatch(querySuccess2.initiate({} as any)),
).rejects.toThrow('reducer error')
})
test('rejected action reducer errors should be thrown', async () => {
const storeRef = faultyStoreFor(api.endpoints.queryFail.matchRejected)
await expect(
storeRef.store.dispatch(queryFail.initiate({} as any)),
).rejects.toThrow('reducer error')
})
})

0 comments on commit e268789

Please sign in to comment.