Skip to content

Commit 25c8cf0

Browse files
alberto911Alberto Pickering
andauthored
fix: data can be null in the downloadMessages response (#139)
Co-authored-by: Alberto Pickering <alberto@airtm.io>
1 parent 7f930db commit 25c8cf0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/LeanplumInbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class LeanplumInbox implements Inbox {
2323
queued: true,
2424
sendNow: true,
2525
response: (data) => {
26-
const response = data.response[0]
26+
const response = data?.response[0]
2727
if (response && response.newsfeedMessages) {
2828
this.messageMap = response.newsfeedMessages
2929

test/specs/LeanplumInbox.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ describe(LeanplumInbox, () => {
5757
expect(handler).toHaveBeenCalledTimes(0)
5858
expect(inbox.messageIds()).toEqual([])
5959
})
60+
61+
it('works when reponse is called with null', () => {
62+
const handler = jest.fn()
63+
64+
inbox.onChanged(handler)
65+
66+
createRequestSpy.mockImplementationOnce(
67+
(method, args, options) => {
68+
options.response(null)
69+
}
70+
)
71+
inbox.downloadMessages()
72+
73+
expect(handler).toHaveBeenCalledTimes(0)
74+
expect(inbox.messageIds()).toEqual([])
75+
})
6076
})
6177

6278
describe('allMessages', () => {

0 commit comments

Comments
 (0)