Skip to content

Commit 2c80abb

Browse files
committed
fix(alm): removeListenerAction and removeListener incorrect return type
1 parent 46fa03d commit 2c80abb

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

packages/action-listener-middleware/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ export function createActionListenerMiddleware<
322322
: entry.predicate === predicate
323323

324324
return matchPredicateOrType && entry.listener === listener
325-
})?.unsubscribe()
325+
})
326+
327+
entry?.unsubscribe()
326328

327329
return !!entry
328330
}

packages/action-listener-middleware/src/tests/listenerMiddleware.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,48 @@ describe('createActionListenerMiddleware', () => {
211211
])
212212
})
213213

214+
test('removeListener returns true if an entry has been unsubscribed, false otherwise', () => {
215+
const listener = jest.fn((_: TestAction1) => {})
216+
217+
middleware.addListener({
218+
actionCreator: testAction1,
219+
listener,
220+
})
221+
222+
expect(
223+
middleware.removeListener({ actionCreator: testAction2, listener })
224+
).toBe(false)
225+
expect(
226+
middleware.removeListener({ actionCreator: testAction1, listener })
227+
).toBe(true)
228+
})
229+
230+
test('dispatch(removeListenerAction({...})) returns true if an entry has been unsubscribed, false otherwise', () => {
231+
const listener = jest.fn((_: TestAction1) => {})
232+
233+
middleware.addListener({
234+
actionCreator: testAction1,
235+
listener,
236+
})
237+
238+
expect(
239+
store.dispatch(
240+
middleware.removeListenerAction({
241+
actionCreator: testAction2,
242+
listener,
243+
})
244+
)
245+
).toBe(false)
246+
expect(
247+
store.dispatch(
248+
middleware.removeListenerAction({
249+
actionCreator: testAction1,
250+
listener,
251+
})
252+
)
253+
).toBe(true)
254+
})
255+
214256
test('can subscribe with a string action type', () => {
215257
const listener = jest.fn((_: AnyAction) => {})
216258

0 commit comments

Comments
 (0)