Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types)(middleware/devtools): fix action type in devtools's setState #1183

Merged
merged 12 commits into from
Aug 18, 2022
Prev Previous commit
Next Next commit
adjusted tests
  • Loading branch information
lucasrabiec committed Aug 11, 2022
commit 9bbf12536409dbb4a6ece3f62af99d59e49b4b6f
32 changes: 12 additions & 20 deletions tests/devtools.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,45 +78,37 @@ describe('If there is no extension installed...', () => {
expect(console.warn).not.toBeCalled()
})
})

describe('When state changes...', () => {
it("sends { type: 'testSetStateName' } as the action with current state", () => {
const { setState } = createTestState()
setState({ count: 10 }, false, 'testSetStateName')
it("sends { type: testSetStateName || 'anonymous`, ...rest } as the action with current state", () => {
lucasrabiec marked this conversation as resolved.
Show resolved Hide resolved
const api = create(
devtools(() => ({ count: 0, foo: 'bar' }), {
name: 'testOptionsName',
enabled: true,
})
)

api.setState({ count: 10 }, false, 'testSetStateName')
expect(extension.send).toHaveBeenLastCalledWith(
{ type: 'testSetStateName' },
{ count: 10, foo: 'bar' }
)
})

it("sends { type: 'testSetStateName', payload: 15 } as the action with current state", () => {
const { setState } = createTestState()
setState({ count: 15 }, false, {
api.setState({ count: 15 }, false, {
type: 'testSetStateName',
payload: 15,
})
expect(extension.send).toHaveBeenLastCalledWith(
{ type: 'testSetStateName', payload: 15 },
{ count: 15, foo: 'bar' }
)
})

it("sends { type: 'anonymous' } as the action with current state", () => {
const { setState } = createTestState()
setState({ count: 5, foo: 'baz' }, true)
api.setState({ count: 5, foo: 'baz' }, true)
expect(extension.send).toHaveBeenLastCalledWith(
{ type: 'anonymous' },
{ count: 5, foo: 'baz' }
)
})

function createTestState() {
return create(
devtools(() => ({ count: 0, foo: 'bar' }), {
name: 'testOptionsName',
enabled: true,
})
)
}
})

describe('when it receives an message of type...', () => {
Expand Down