Skip to content

Commit 289c711

Browse files
committed
chore: fixed tests
1 parent caee446 commit 289c711

File tree

7 files changed

+32
-11
lines changed

7 files changed

+32
-11
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
import Wallet from '../../../src/bricks/wallet';
3+
import { PUBLIC_KEY } from '../../constants';
4+
5+
import initMercadoPago from '../../../src/mercadoPago/initMercadoPago';
6+
7+
initMercadoPago(PUBLIC_KEY);
8+
9+
const ExampleSimpleWalletBrick = () => {
10+
return (
11+
<Wallet initialization={{ preferenceId: 'YOUR_PREFERENCE_ID' }} id="custom-container-id" />
12+
);
13+
};
14+
15+
export default ExampleSimpleWalletBrick;

src/bricks/util/initial/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-empty-function */
12
import { IBrickError } from '../types/common';
23

34
const onSubmitDefault = async () => {};

src/bricks/util/initial/initial.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { onErrorDefault, onSubmitDefault, onReadyDefault } from './index';
33
describe('Test default functions', () => {
44
test('Console error should have been called when onErrorDefault is call', () => {
55
// Mock the console.error to not generate a console.error when we run test.
6-
const logSpy = jest.spyOn(global.console, 'error').mockImplementation(() => {});
6+
const logSpy = jest.spyOn(global.console, 'error').mockImplementation(jest.fn());
77
onErrorDefault({
88
type: 'critical',
99
cause: 'settings_empty',
@@ -15,10 +15,13 @@ describe('Test default functions', () => {
1515

1616
logSpy.mockRestore();
1717
});
18-
test('Should onSubmitDefault be called', () => {
19-
expect(onSubmitDefault()).resolves.toBe({});
18+
19+
test('Should onSubmitDefault be called', async () => {
20+
const response = await onSubmitDefault();
21+
expect(response).toEqual(undefined);
2022
});
23+
2124
test('Should onReadyDefault be called', () => {
22-
expect(onReadyDefault()).toBe(undefined);
25+
expect(onReadyDefault()).toEqual(undefined);
2326
});
2427
});

src/bricks/util/renderBrick/renderBrick.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ declare global {
99

1010
describe('Test renderBrick', () => {
1111
test('should return a render Brick', async () => {
12-
const mock = jest.fn();
12+
const createMock = jest.fn();
1313
MercadoPagoInstance.publicKey = 'PUBLIC_KEY';
14-
MercadoPagoInstance.instanceMercadoPago = {
14+
MercadoPagoInstance.getInstance = jest.fn().mockResolvedValue({
1515
bricks: function () {
1616
return {
17-
create: mock,
17+
create: createMock,
1818
};
1919
},
2020
getIdentificationTypes: jest.fn(),
@@ -28,16 +28,17 @@ describe('Test renderBrick', () => {
2828
updateCardToken: jest.fn(),
2929
create: jest.fn(),
3030
},
31-
};
31+
});
3232

3333
const WalletBrickConfig = {
3434
settings: {},
3535
name: 'brickTest',
36-
containerIdcontainerId: 'brickTest_container',
3736
controller: 'brickTestController',
37+
containerId: 'brickTest_container',
3838
};
3939

4040
await initBrick(WalletBrickConfig);
41-
expect(mock).toBeCalledTimes(1);
41+
expect(createMock).toHaveBeenCalledTimes(1);
42+
expect(createMock).toHaveBeenCalledWith('brickTest', 'brickTest_container', {});
4243
});
4344
});

src/bricks/wallet/walletBrick.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('Test Wallet Brick Component', () => {
1212

1313
expect(element.container.querySelector('#walletBrick_container')).toBeTruthy();
1414
});
15+
1516
test('should found the id of Wallet Brick div if specified', async () => {
1617
MercadoPagoInstance.publicKey = 'PUBLIC_KEY';
1718
const element = await render(

src/mercadoPago/initMercadoPago/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class MercadoPagoInstance {
55
static publicKey: string | null = null;
66
static options: TOptions = {};
77
static instanceMercadoPago?: TInstanceMercadoPago = undefined;
8-
static loadedInstanceMercadoPago: boolean = false;
8+
static loadedInstanceMercadoPago = false;
99

1010
static async getInstance() {
1111
if (this.publicKey) {

0 commit comments

Comments
 (0)