Cannot perform 'get' on a proxy that has been revoked (When testing reducer with Jest)
See original GitHub issueIf you have a reducer that uses an util function and you wan’t to mock and check the call of the function the test will break:
const { reducer, actions } = createSlice({
name: 'aSlice',
reducers: {
doSomething(state, action) {
someUtilFunc(state, action.payload)
}
}
test('reducer should call someUtilFunc with state and payload on action doSomething', () => {
const myPayload = { name: 'foo' }
const state = { name: 'bar' }
reducer(state, actions.doSomething(myPayload))
expect(someUtilFunc).toHaveBeenCalledWith(state, myPayload)
})
expect(someUtilFunc).toHaveBeenCalledWith(state, myPayload) this line will throw a Cannot perform 'get' on a proxy that has been revoked error.
I’m guessing this is because immerJs proxy is revoked when the reducer call is completed. I could pass {...state} to my someUtilFunc but this is impractical and I don’t wan’t my tests to influence my code.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
Unhandled Rejection (TypeError): Cannot perform 'get' on a ...
You're trying to run async logic in a reducer, and that is never allowed in Redux - reducers must not have side effects....
Read more >Cannot perform 'get' on a proxy that has been revoked #43
Hello! Im getting the error Cannot perform 'get' on a proxy that has been revoked in jest tests. ... In browser everything works...
Read more >cannot perform 'get' on a proxy that has been revoked, typeerror
This object is wrapped with a revocable proxy. When this method completes, the proxy is revoked.
Read more >[Solved]-How can i fix this type of error?-Reactjs
How Do I Fix this Sequelize Database Error when trying to do a POST method? ... promise) TypeError: Cannot perform 'get' on a...
Read more >@reduxjs/toolkit: Cannot perform 'get' on a proxy that has ...
@reduxjs/toolkit: Cannot perform 'get' on a proxy that has been revoked 에러(reducer 규칙 지키기). 2pandi·2022년 10월 21일. 0. Reactreduxredux-toolkit.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This really isn’t even an RTK issue specifically - it’s about Immer only using proxies inside of
produce/createNextState.I don’t think there’s anything we can or should do here.
Sorry, I didn’t mean that I didn’t agree with you! I found a way to solve the problem anyways and it works pretty well. I just wanted to give some context on why I am testing with mocks in a reducer.