Skip to content

Commit

Permalink
fix merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Apr 18, 2022
1 parent b1c4d2f commit 826eb58
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions tests/devtools.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ describe('If there is no extension installed...', () => {
describe('When state changes...', () => {
it("sends { type: setStateName || 'anonymous` } as the action with current state", () => {
const api = create(
devtools(() => ({ count: 0, foo: 'bar' }), { name: 'testOptionsName' })
devtools(() => ({ count: 0, foo: 'bar' }), {
name: 'testOptionsName',
enabled: true,
})
)
api.setState({ count: 10 }, false, 'testSetStateName')
expect(extension.send).toHaveBeenLastCalledWith(
Expand All @@ -101,7 +104,7 @@ describe('when it receives an message of type...', () => {
describe('ACTION...', () => {
it('does nothing', () => {
const initialState = { count: 0 }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
const setState = jest.spyOn(api, 'setState')

;(extensionSubscriber as (message: any) => void)({
Expand All @@ -115,7 +118,7 @@ describe('when it receives an message of type...', () => {

it('unless action type is __setState', () => {
const initialState = { count: 0 }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))

;(extensionSubscriber as (message: any) => void)({
type: 'ACTION',
Expand All @@ -127,7 +130,7 @@ describe('when it receives an message of type...', () => {

it('does nothing even if there is `api.dispatch`', () => {
const initialState = { count: 0 }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
;(api as any).dispatch = jest.fn()
const setState = jest.spyOn(api, 'setState')

Expand All @@ -143,7 +146,7 @@ describe('when it receives an message of type...', () => {

it('dispatches with `api.dispatch` when `api.dispatchFromDevtools` is set to true', () => {
const initialState = { count: 0 }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
;(api as any).dispatch = jest.fn()
;(api as any).dispatchFromDevtools = true
const setState = jest.spyOn(api, 'setState')
Expand All @@ -162,7 +165,7 @@ describe('when it receives an message of type...', () => {

it('does not throw for unsupported payload', () => {
const initialState = { count: 0 }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
;(api as any).dispatch = jest.fn()
;(api as any).dispatchFromDevtools = true
const setState = jest.spyOn(api, 'setState')
Expand Down Expand Up @@ -209,7 +212,7 @@ describe('when it receives an message of type...', () => {
describe('DISPATCH and payload of type...', () => {
it('RESET, it inits with initial state', () => {
const initialState = { count: 0 }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
api.setState({ count: 1 })

extension.send.mockClear()
Expand All @@ -225,7 +228,7 @@ describe('when it receives an message of type...', () => {

it('COMMIT, it inits with current state', () => {
const initialState = { count: 0 }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
api.setState({ count: 2 })
const currentState = api.getState()

Expand All @@ -242,7 +245,7 @@ describe('when it receives an message of type...', () => {
describe('ROLLBACK...', () => {
it('it updates state without recording and inits with `message.state`', () => {
const initialState = { count: 0, increment: () => {} }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
const newState = { foo: 'bar' }

extension.send.mockClear()
Expand All @@ -263,7 +266,7 @@ describe('when it receives an message of type...', () => {
it('does not throw for unparsable `message.state`', () => {
const increment = () => {}
const initialState = { count: 0, increment }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
const originalConsoleError = console.error
console.error = jest.fn()

Expand Down Expand Up @@ -297,7 +300,7 @@ describe('when it receives an message of type...', () => {
const increment = () => {}
it('it updates state without recording with `message.state`', () => {
const initialState = { count: 0, increment }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
const newState = { foo: 'bar' }

extension.send.mockClear()
Expand All @@ -312,7 +315,7 @@ describe('when it receives an message of type...', () => {

it('does not throw for unparsable `message.state`', () => {
const initialState = { count: 0, increment: () => {} }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
const originalConsoleError = console.error
console.error = jest.fn()

Expand Down Expand Up @@ -343,7 +346,7 @@ describe('when it receives an message of type...', () => {
describe('JUMP_TO_ACTION...', () => {
it('it updates state without recording with `message.state`', () => {
const initialState = { count: 0, increment: () => {} }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
const newState = { foo: 'bar' }

extension.send.mockClear()
Expand All @@ -359,7 +362,7 @@ describe('when it receives an message of type...', () => {
it('does not throw for unparsable `message.state`', () => {
const increment = () => {}
const initialState = { count: 0, increment }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
const originalConsoleError = console.error
console.error = jest.fn()

Expand Down Expand Up @@ -389,7 +392,7 @@ describe('when it receives an message of type...', () => {

it('IMPORT_STATE, it updates state without recording and inits the last computedState', () => {
const initialState = { count: 0, increment: () => {} }
const api = create(devtools(() => initialState))
const api = create(devtools(() => initialState, { enabled: true }))
const nextLiftedState = {
computedStates: [{ state: { count: 4 } }, { state: { count: 5 } }],
}
Expand All @@ -410,7 +413,7 @@ describe('when it receives an message of type...', () => {
})

it('PAUSE_RECORDING, it toggles the sending of actions', () => {
const api = create(devtools(() => ({ count: 0 })))
const api = create(devtools(() => ({ count: 0 }), { enabled: true }))

api.setState({ count: 1 }, false, 'increment')
expect(extension.send).toHaveBeenLastCalledWith(
Expand Down Expand Up @@ -460,7 +463,8 @@ describe('with redux middleware', () => {
count: count + (type === 'INCREMENT' ? 1 : -1),
}),
{ count: 0 }
)
),
{ enabled: true }
)
)
;(api as any).dispatch({ type: 'INCREMENT' })
Expand Down Expand Up @@ -497,7 +501,7 @@ it('works in non-browser env', () => {
global.window = undefined as any

expect(() => {
create(devtools(() => ({ count: 0 })))
create(devtools(() => ({ count: 0 }), { enabled: true }))
}).not.toThrow()

global.window = originalWindow
Expand All @@ -508,14 +512,14 @@ it('works in react native env', () => {
global.window = {} as any

expect(() => {
create(devtools(() => ({ count: 0 })))
create(devtools(() => ({ count: 0 }), { enabled: true }))
}).not.toThrow()

global.window = originalWindow
})

it('preserves isRecording after setting from devtools', () => {
const api = create(devtools(() => ({ count: 0 })))
const api = create(devtools(() => ({ count: 0 }), { enabled: true }))
;(extensionSubscriber as (message: any) => void)({
type: 'DISPATCH',
payload: { type: 'PAUSE_RECORDING' },
Expand Down

0 comments on commit 826eb58

Please sign in to comment.