---
# System prepended metadata

title: Template de testes unitarios

---

# Template de teste unitário usando o shallow do Enzyme.

```react
import React from 'react';
import { shallow } from 'enzyme';
import Lion from '@sollar/lion';
import MyComponent from '../MyComponent.jsx';
import MOCKED_PROPS from '../__mocks__/ProductsTabMock.js';

jest.mock('@wealthlabs', () => ({
    formatMonetaryValue: jest.fn().mockImplementation((value, currencyCode, decimalPlaces = 2) => {
        if (currencyCode) {
            return `${currencyCode ?? ''} ${value.toFixed(decimalPlaces)}`;
        }

        return `${value.toFixed(decimalPlaces)}`;
    }),
    formatNumber: jest.fn().mockImplementation((value, decimals) => {
        return `${value.toFixed(decimals)}`;
    }),
    setLanguage: jest.fn(),
    getLanguage: jest.fn(),
    addMessages: jest.fn(),
    getMessage: jest.fn((key) => key),
}));

describe('ProductsTab', () => {
    let wrapper;
    let instance;

    beforeAll(() => {    
        wrapper = shallow(<MyComponent {...MOCKED_PROPS} />);
        instance = wrapper.instance();
    });
    beforeEach(() => {
        jest.clearAllMocks();
    });

    describe('Function name', () => {
        it('Should do something', () => {
            console.log(wrapper.debug());
            jestExpect(Lion.formatMonetaryValue).toHaveBeenCalledTimes(1);
            jestExpect(wrapper.find('someElement').prop('attribute')).toBe(true);
        });
    });
    
});
```