Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

[Bug] Jest encountered an unexpected token

Sempre que executo os testes, o teste de Transações falha com a seguinte mensagem:

FAIL  src/componentes/Extrato/Transacoes/Transacoes.test.jsx
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation
``
3 respostas

...continuando:

Details:

SyntaxError: /home/renan/GitHub/bytebank/src/componentes/Extrato/Transacoes/Transacoes.test.jsx: Invalid left-hand side in assignment expression. (14:4)

  12 |     const valorTransacao = screen.getByTestId('valorTransacao')
  13 |     
> 14 |     expect(tipoTransacao) = screen.toHaveTextContent('Depósito')
     |     ^
  15 |     expect(valorTransacao) = screen.toHaveTextContent('R$ 100')
  16 | })
  17 |

  at toParseError (node_modules/.pnpm/@babel+parser@7.24.5/node_modules/@babel/parser/src/parse-error.ts:74:19)
  at FlowParserMixin.raise (node_modules/.pnpm/@babel+parser@7.24.5/node_modules/@babel/parser/src/tokenizer/index.ts:1490:19)
  at FlowParserMixin.checkLVal (node_modules/.pnpm/@babel+parser@7.24.5/node_modules/@babel/parser/src/parser/lval.ts:668:12)
  at FlowParserMixin.parseMaybeAssign (node_modules/.pnpm/@babel+parser@7.24.5/node_modules/@babel/parser/src/parser/expression.ts:336:12)
  at FlowParserMixin.parseMaybeAssign (node_modules/.pnpm/@babel+parser@7.24.5/node_modules/@babel/parser/src/plugins/flow/index.ts:3060:20)
  at FlowParserMixin.parseExpressionBase (node_modules/.pnpm/@babel+parser@7.24.5/node_modules/@babel/parser/src/parser/expression.ts:220:23)
  (...) (ficou grande demais para postar aqui)

Já tentei fazer o que diz nos links indicados, mas não resolve.

Tentei também a solução apontada em https://stackoverflow.com/questions/65717630/jest-encountered-an-unexpected-token-when-working-with-react-typescript, mas também não funcionou.

Olá, Tudo bem?

Eu vi que tem um pequeno erro no nome do seu arquivo.

src/componentes/Extrato/Transacoes/Transacoes.test.jsx

Você salvou o arquivo de testes como um JSX, mas na verdade ele é apenas um arquivo .js mesmo.

Acredito que fazendo essa correção o teste volta a funcionar.

Grande abraço!

solução!

Descobri o problema. Eu estava usando:

expect(tipoTransacao) = screen.toHaveTextContent('Depósito')

Ao invés de

expect(tipoTransacao).toHaveTextContent('Depósito')

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software