Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correção dos testes #95

Merged
merged 6 commits into from
Oct 11, 2020
Merged

Correção dos testes #95

merged 6 commits into from
Oct 11, 2020

Conversation

luistak
Copy link
Collaborator

@luistak luistak commented Oct 10, 2020

O que

Correção dos testes:

  • src/components/AnswersProvider/AnswersProvider.test.js
  • src/components/Question/Question.test.js
  • src/pages/Ranking/Ranking.test.js
  • src/App.test.js

Adição do jsdom como env do jest corrigindo este problema

Verificações

Comment on lines +79 to +83
const nameInput = screen.getByLabelText('Nome completo');
userEvent.type(nameInput, 'Kleber da silva');

const cityInput = screen.getByLabelText('Cidade');
userEvent.selectOptions(cityInput, 'campinas');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Além dos wrappers, estavam faltando estes dois campos que eram obrigatórios também

projectId: jest.fn(12345),
}),
auth: jest.fn().mockReturnThis(),
signInWithCustomToken: jest.fn().mockResolvedValue(),
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creio que estes e outros mocks podem ser melhorados no futuro criando "customRenders", para cada um desses providers como neste exemplo

jest.mock('firebase/app', () => {
return {
firestore: jest.fn(() => ({
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Há uma outra lib que resolve isso, mas não é 100% segura então resolvi adicionar somente o necessário para o teste funcionar

expect(newCandidates.length).toEqual(20);
act(() => {
userEvent.click(loadMorebutton);
jest.runOnlyPendingTimers();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utilizei para rodar os timers do setTimeout interno do componente

Copy link
Contributor

@victormiguez victormiguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Massa, muito obrigado pela contribuição, @luistak!

@victormiguez victormiguez merged commit bc30ede into Minhacps:develop Oct 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants