Skip to content

Commit

Permalink
chore: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
icaldana committed Dec 17, 2024
1 parent caee446 commit 289c711
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
15 changes: 15 additions & 0 deletions examples/bricks/WalletBrick/6-Custom-ContainerId.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import Wallet from '../../../src/bricks/wallet';
import { PUBLIC_KEY } from '../../constants';

import initMercadoPago from '../../../src/mercadoPago/initMercadoPago';

initMercadoPago(PUBLIC_KEY);

const ExampleSimpleWalletBrick = () => {
return (
<Wallet initialization={{ preferenceId: 'YOUR_PREFERENCE_ID' }} id="custom-container-id" />
);
};

export default ExampleSimpleWalletBrick;
1 change: 1 addition & 0 deletions src/bricks/util/initial/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { IBrickError } from '../types/common';

const onSubmitDefault = async () => {};
Expand Down
11 changes: 7 additions & 4 deletions src/bricks/util/initial/initial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { onErrorDefault, onSubmitDefault, onReadyDefault } from './index';
describe('Test default functions', () => {
test('Console error should have been called when onErrorDefault is call', () => {
// Mock the console.error to not generate a console.error when we run test.
const logSpy = jest.spyOn(global.console, 'error').mockImplementation(() => {});
const logSpy = jest.spyOn(global.console, 'error').mockImplementation(jest.fn());
onErrorDefault({
type: 'critical',
cause: 'settings_empty',
Expand All @@ -15,10 +15,13 @@ describe('Test default functions', () => {

logSpy.mockRestore();
});
test('Should onSubmitDefault be called', () => {
expect(onSubmitDefault()).resolves.toBe({});

test('Should onSubmitDefault be called', async () => {
const response = await onSubmitDefault();
expect(response).toEqual(undefined);
});

test('Should onReadyDefault be called', () => {
expect(onReadyDefault()).toBe(undefined);
expect(onReadyDefault()).toEqual(undefined);
});
});
13 changes: 7 additions & 6 deletions src/bricks/util/renderBrick/renderBrick.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ declare global {

describe('Test renderBrick', () => {
test('should return a render Brick', async () => {
const mock = jest.fn();
const createMock = jest.fn();
MercadoPagoInstance.publicKey = 'PUBLIC_KEY';
MercadoPagoInstance.instanceMercadoPago = {
MercadoPagoInstance.getInstance = jest.fn().mockResolvedValue({
bricks: function () {
return {
create: mock,
create: createMock,
};
},
getIdentificationTypes: jest.fn(),
Expand All @@ -28,16 +28,17 @@ describe('Test renderBrick', () => {
updateCardToken: jest.fn(),
create: jest.fn(),
},
};
});

const WalletBrickConfig = {
settings: {},
name: 'brickTest',
containerIdcontainerId: 'brickTest_container',
controller: 'brickTestController',
containerId: 'brickTest_container',
};

await initBrick(WalletBrickConfig);
expect(mock).toBeCalledTimes(1);
expect(createMock).toHaveBeenCalledTimes(1);
expect(createMock).toHaveBeenCalledWith('brickTest', 'brickTest_container', {});
});
});
1 change: 1 addition & 0 deletions src/bricks/wallet/walletBrick.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('Test Wallet Brick Component', () => {

expect(element.container.querySelector('#walletBrick_container')).toBeTruthy();
});

test('should found the id of Wallet Brick div if specified', async () => {
MercadoPagoInstance.publicKey = 'PUBLIC_KEY';
const element = await render(
Expand Down
2 changes: 1 addition & 1 deletion src/mercadoPago/initMercadoPago/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class MercadoPagoInstance {
static publicKey: string | null = null;
static options: TOptions = {};
static instanceMercadoPago?: TInstanceMercadoPago = undefined;
static loadedInstanceMercadoPago: boolean = false;
static loadedInstanceMercadoPago = false;

static async getInstance() {
if (this.publicKey) {
Expand Down

0 comments on commit 289c711

Please sign in to comment.