From 140218075f0f9ce00c0e930a7b18db5629bb1ab0 Mon Sep 17 00:00:00 2001 From: Sandile Date: Fri, 11 Feb 2022 16:59:17 +0200 Subject: [PATCH] fix(actions-core): Added scrollTo with no params error test. --- .../actions-core/src/actions/ScrollTo.test.js | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/plugins/actions/actions-core/src/actions/ScrollTo.test.js b/packages/plugins/actions/actions-core/src/actions/ScrollTo.test.js index c9aa7d396..f4bd3f9cd 100644 --- a/packages/plugins/actions/actions-core/src/actions/ScrollTo.test.js +++ b/packages/plugins/actions/actions-core/src/actions/ScrollTo.test.js @@ -64,6 +64,18 @@ beforeEach(() => { mockElemScrollIntoView.mockReset(); }); +const RealDate = Date; +const mockDate = jest.fn(() => ({ date: 0 })); +mockDate.now = jest.fn(() => 0); + +beforeAll(() => { + global.Date = mockDate; +}); + +afterAll(() => { + global.Date = RealDate; +}); + test('ScrollTo with no params', async () => { const rootBlock = { id: 'block:root:root:0', @@ -95,8 +107,34 @@ test('ScrollTo with no params', async () => { rootBlock, }); const button = context._internal.RootBlocks.map['block:root:button:0']; - button.triggerEvent({ name: 'onClick' }); - expect(mockWindowScrollTo.mock.calls).toEqual([]); + const res = await button.triggerEvent({ name: 'onClick' }); + expect(res).toEqual({ + blockId: 'button', + bounced: false, + endTimestamp: { date: 0 }, + error: { + action: { + id: 'a', + type: 'ScrollTo', + }, + error: { + error: new Error('Invalid ScrollTo, check action params. Received "undefined".'), + index: 0, + type: 'ScrollTo', + }, + }, + event: undefined, + eventName: 'onClick', + responses: { + a: { + error: new Error('Invalid ScrollTo, check action params. Received "undefined".'), + index: 0, + type: 'ScrollTo', + }, + }, + startTimestamp: { date: 0 }, + success: false, + }); }); test('ScrollTo with no blockId', async () => {