Skip to content

Instantly share code, notes, and snippets.

@IsTheJack
Created February 8, 2018 16:54
Show Gist options
  • Select an option

  • Save IsTheJack/83cee7280d1538f39c7f8ed06fc21568 to your computer and use it in GitHub Desktop.

Select an option

Save IsTheJack/83cee7280d1538f39c7f8ed06fc21568 to your computer and use it in GitHub Desktop.
// actions.test.js
// Importando o arquivo onde terá a função acoplada à função testada
import * as punkapi from './path/to/file';
// Importando o aquivo onde terá a função testada
import * as actions from './actions';
// Arquivo com as constantes dos types usados nas actions
import * as types from './types';
// ...
it('must to return success action on success', () => {
jest
.spyOn(punkapi, 'getBeers')
.mockImplementation(() => Promise.resolve({ data: { mock: 'mock' } }));
// Fazendo um mock simples da função de dispatch
const dispatchMock = jest.fn()
// Chamando a função testada e passando o mock do dispatch
const promise = actions.fetchBeers()(dispatchMock);
});
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment