Skip to content

Commit 383d932

Browse files
committed
test(devtools): test if the connection removed after cleanup
1 parent 5d8f2aa commit 383d932

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

tests/devtools.test.tsx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ const extensionConnector = {
9898
subscribers.push(f)
9999
return () => {}
100100
}),
101-
unsubscribe: vi.fn(),
101+
unsubscribe: vi.fn(() => {
102+
connectionMap.delete(
103+
areNameUndefinedMapsNeeded ? options.testConnectionId : key,
104+
)
105+
}),
102106
send: vi.fn(),
103107
init: vi.fn(),
104108
error: vi.fn(),
@@ -2453,9 +2457,35 @@ describe('cleanup', () => {
24532457
it('should unsubscribe from devtools when cleanup is called', async () => {
24542458
const options = { name: 'test' }
24552459
const store = createStore(devtools(() => ({ count: 0 }), options))
2460+
const [connection] = getNamedConnectionApis(options.name)
24562461
store.devtools.cleanup()
24572462

2458-
const [connection] = getNamedConnectionApis(options.name)
24592463
expect(connection.unsubscribe).toHaveBeenCalledTimes(1)
24602464
})
2465+
2466+
it('should remove store from tracked connection after cleanup', async () => {
2467+
const options = {
2468+
name: 'test-store-name',
2469+
store: 'test-store-id',
2470+
enabled: true,
2471+
}
2472+
2473+
const store1 = createStore(devtools(() => ({ count: 0 }), options))
2474+
store1.devtools.cleanup()
2475+
const store2 = createStore(devtools(() => ({ count: 0 }), options))
2476+
2477+
const [connection] = getNamedConnectionApis(options.name)
2478+
2479+
store2.setState({ count: 15 }, false, 'updateCount')
2480+
expect(connection.send).toHaveBeenLastCalledWith(
2481+
{ type: `${options.store}/updateCount` },
2482+
{ [options.store]: { count: 15 } },
2483+
)
2484+
2485+
store1.setState({ count: 20 }, false, 'ignoredAction')
2486+
expect(connection.send).not.toHaveBeenLastCalledWith(
2487+
{ type: `${options.store}/ignoredAction` },
2488+
expect.anything(),
2489+
)
2490+
})
24612491
})

0 commit comments

Comments
 (0)