From 85be7bcbc41ab1ddee56b495d3e6b511d7258225 Mon Sep 17 00:00:00 2001 From: Ian Lin Date: Wed, 10 Jul 2024 18:28:54 +0800 Subject: [PATCH] add jest test for collect inputs --- src/__tests__/functions.test.ts | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/__tests__/functions.test.ts b/src/__tests__/functions.test.ts index a50e8b70..cab0467c 100644 --- a/src/__tests__/functions.test.ts +++ b/src/__tests__/functions.test.ts @@ -42,6 +42,38 @@ const mockLocations = [ }, ]; +const mockCollectInputsReturns = [ + { + skipped: false, + text: '_text', + toggles:[], + }, + { + skipped: false, + email: '_email', + toggles:[], + },{ + skipped: false, + numericString: '_numericString', + toggles:[], + }, + { + skipped: false, + phone: '_phone', + toggles:[], + }, + { + skipped: false, + signatureSvg: '_signatureSvg', + toggles:[], + }, + { + skipped: false, + selection: '_selection', + toggles:[], + } +] + describe('functions.test.ts', () => { describe('Functions snapshot', () => { it('ensure there are no unexpected changes to the functions exports', () => { @@ -127,6 +159,7 @@ describe('functions.test.ts', () => { .mockImplementation(() => ({})), cancelCollectSetupIntent: jest.fn().mockImplementation(() => ({})), setSimulatedCard: jest.fn(), + collectInputs: jest.fn().mockImplementation(() => ({ collectInputResults: mockCollectInputsReturns })), })); }); @@ -369,6 +402,14 @@ describe('functions.test.ts', () => { const functions = require('../functions'); await expect(functions.setSimulatedCard('_number')).resolves.toEqual({}); }); + + it('collectInputs returns a proper value', async () => { + const functions = require('../functions'); + await expect(functions.collectInputs()).resolves.toEqual({ + error: undefined, + collectInputResults: mockCollectInputsReturns, + }); + }); }); describe('Functions error results', () => { @@ -461,6 +502,7 @@ describe('functions.test.ts', () => { cancelInstallingUpdate: jest.fn().mockRejectedValue('_error'), installAvailableUpdate: jest.fn().mockRejectedValue('_error'), initialize: jest.fn().mockImplementation(() => ({ error: '_error' })), + collectInputs: jest.fn().mockImplementation(() => ({ error: '_error'})), })); }); @@ -687,6 +729,13 @@ describe('functions.test.ts', () => { }); }); }); + + it('collectInputs returns a proper value', async () => { + const functions = require('../functions'); + await expect(functions.collectInputs()).resolves.toEqual({ + error: '_error', + }); + }); }); // workaround to avoiding producing d.ts files that introduces types conflicts