diff --git a/src/LeanplumInbox.ts b/src/LeanplumInbox.ts index a629d98..62118ce 100644 --- a/src/LeanplumInbox.ts +++ b/src/LeanplumInbox.ts @@ -23,7 +23,7 @@ export default class LeanplumInbox implements Inbox { queued: true, sendNow: true, response: (data) => { - const response = data.response[0] + const response = data?.response[0] if (response && response.newsfeedMessages) { this.messageMap = response.newsfeedMessages diff --git a/test/specs/LeanplumInbox.test.ts b/test/specs/LeanplumInbox.test.ts index f0abe15..d6123b2 100644 --- a/test/specs/LeanplumInbox.test.ts +++ b/test/specs/LeanplumInbox.test.ts @@ -57,6 +57,22 @@ describe(LeanplumInbox, () => { expect(handler).toHaveBeenCalledTimes(0) expect(inbox.messageIds()).toEqual([]) }) + + it('works when reponse is called with null', () => { + const handler = jest.fn() + + inbox.onChanged(handler) + + createRequestSpy.mockImplementationOnce( + (method, args, options) => { + options.response(null) + } + ) + inbox.downloadMessages() + + expect(handler).toHaveBeenCalledTimes(0) + expect(inbox.messageIds()).toEqual([]) + }) }) describe('allMessages', () => {