Os meus testes passam mas mesmo assim continua tendo um erro mesmo eu ajustando meu código para estar exatamente igual o da instrutora.
Eu não mexi em nada do código original, apenas fiz o teste como na aula.
import Transacao from "./Transacao";
import React from "react";
import { render } from "@testing-library/react";
describe("Componente de transação do extrato", () => {
it("O snapshot do componente deve permanecer sempre o mesmo", () => {
const { container } = render(
<Transacao data="08/09/2020" tipo="saque" valor="20.00" />
);
expect(container.firstChild).toMatchSnapshot();
});
});
ERRO
PASS src/transacoes/Transacao.test.js
PASS src/App.test.js
Test Suites: 2 passed, 2 total
Tests: 6 passed, 6 total
Snapshots: 1 passed, 1 total
Time: 1.984s, estimated 2s
Ran all test suites related to changed files.
Watch Usage
› Press a to run all tests.
› Press f to run only failed tests.
› Press q to quit watch mode.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press Enter to trigger a test run.
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Warning: An update to App inside a test was not wrapped in act(...).
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
This ensures that you're testing the behavior the user would see in the browser. Learn more at https://fb.me/react-wrap-tests-with-act
in App (at App.test.js:8)".
38 | }
39 |
> 40 | useEffect(() => {
| ^
41 | obterSaldo();
42 | carregarTransacoes();
43 | }, [saldo])
at console.error (node_modules/@jest/console/build/BufferedConsole.js:163:10)
at printWarning (node_modules/react-dom/cjs/react-dom.development.js:88:30)
at error (node_modules/react-dom/cjs/react-dom.development.js:60:5)
at warnIfNotCurrentlyActingUpdatesInDEV (node_modules/react-dom/cjs/react-dom.development.js:23284:7)
at dispatchAction (node_modules/react-dom/cjs/react-dom.development.js:15656:9)
at carregarTransacoes (src/App.js:40:5)
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
in App (at App.test.js:8)".
38 | }
39 |
> 40 | useEffect(() => {
| ^
41 | obterSaldo();
42 | carregarTransacoes();
43 | }, [saldo])
at console.error (node_modules/@jest/console/build/BufferedConsole.js:163:10)
at printWarning (node_modules/react-dom/cjs/react-dom.development.js:88:30)
at error (node_modules/react-dom/cjs/react-dom.development.js:60:5)
at warnAboutUpdateOnUnmountedFiberInDEV (node_modules/react-dom/cjs/react-dom.development.js:23161:5)
at scheduleUpdateOnFiber (node_modules/react-dom/cjs/react-dom.development.js:21169:5)
at dispatchAction (node_modules/react-dom/cjs/react-dom.development.js:15660:5)
at carregarTransacoes (src/App.js:40:5)