Skip to content

Commit

Permalink
add jest test for collect inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ianlin-bbpos committed Jul 11, 2024
1 parent 6bc2f65 commit 85be7bc
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/__tests__/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -127,6 +159,7 @@ describe('functions.test.ts', () => {
.mockImplementation(() => ({})),
cancelCollectSetupIntent: jest.fn().mockImplementation(() => ({})),
setSimulatedCard: jest.fn(),
collectInputs: jest.fn().mockImplementation(() => ({ collectInputResults: mockCollectInputsReturns })),
}));
});

Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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'})),
}));
});

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 85be7bc

Please sign in to comment.