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

Erro no toHaveFocus()

Já revirei o código inteiro, e não consigo fazer o teste do toHaveFocus passar.

  console.error
    Error: Not implemented: HTMLFormElement.prototype.submit
        at module.exports (/Users/leonardofigueiro/WebProjects/reacttypescript6/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17)
        at HTMLFormElementImpl.submit (/Users/leonardofigueiro/WebProjects/reacttypescript6/node_modules/jsdom/lib/jsdom/living/nodes/HTMLFormElement-impl.js:88:5)
        at HTMLFormElementImpl._doSubmit (/Users/leonardofigueiro/WebProjects/reacttypescript6/node_modules/jsdom/lib/jsdom/living/nodes/HTMLFormElement-impl.js:80:10)
        at HTMLButtonElementImpl._activationBehavior (/Users/leonardofigueiro/WebProjects/reacttypescript6/node_modules/jsdom/lib/jsdom/living/nodes/HTMLButtonElement-impl.js:23:14)
        at HTMLButtonElementImpl._dispatch (/Users/leonardofigueiro/WebProjects/reacttypescript6/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:240:26)
        at HTMLButtonElementImpl.dispatchEvent (/Users/leonardofigueiro/WebProjects/reacttypescript6/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
        at HTMLButtonElement.dispatchEvent (/Users/leonardofigueiro/WebProjects/reacttypescript6/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
        at /Users/leonardofigueiro/WebProjects/reacttypescript6/node_modules/@testing-library/dom/dist/events.js:25:20
        at /Users/leonardofigueiro/WebProjects/reacttypescript6/node_modules/@testing-library/react/dist/pure.js:66:16
        at batchedUpdates$1 (/Users/leonardofigueiro/WebProjects/reacttypescript6/node_modules/react-dom/cjs/react-dom.development.js:22380:12) undefined

      at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45)
      at module.exports (node_modules/jsdom/lib/jsdom/browser/not-implemented.js:12:26)
      at HTMLFormElementImpl.submit (node_modules/jsdom/lib/jsdom/living/nodes/HTMLFormElement-impl.js:88:5)
      at HTMLFormElementImpl._doSubmit (node_modules/jsdom/lib/jsdom/living/nodes/HTMLFormElement-impl.js:80:10)
      at HTMLButtonElementImpl._activationBehavior (node_modules/jsdom/lib/jsdom/living/nodes/HTMLButtonElement-impl.js:23:14)
      at HTMLButtonElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:240:26)

 FAIL  src/components/Form.test.tsx
  ✓ Testar o formulario para impedir cadastro quando o input estiver vazio (128 ms)
  ✕ Adicionar um participante caso o input esteja preenchido (108 ms)

  ● Adicionar um participante caso o input esteja preenchido

    expect(element).toHaveFocus()

    Expected element with focus:
      <input placeholder="Insira os nomes dos participantes" type="text" value="Ana Katarina" />
    Received element with focus:
      <body><div><form><input placeholder="Insira os nomes dos participantes" type="text" value="Ana Katarina" /><button type="submit">Adicionar</button></form></div></body>

      35 |     fireEvent.click(button)
      36 |     //garantir que o cursor voltará pro input (foco ativo)
    > 37 |     expect(input).toHaveFocus()
         |                   ^
      38 |     //garantir que o input fique vazio
      39 |     expect(input).toHaveValue('')
      40 | })

      at Object.<anonymous> (src/components/Form.test.tsx:37:19)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        3.563 s
Ran all test suites.

Watch Usage: Press w to show more.

Segue o link do github: https://github.com/leonardofigueiro/reacttypescript6

Ao abrir o arquivo do teste, verifico que o import acusa que o getByPlaceholderText é declarado, mas nunca é lido.

2 respostas
solução!

Encontrei o erro. Era na chada da função para adicionar participante no Form.

Oi Leonardo, tudo bem?

Que bom que encontrou o erro! Irei finalizar o tópico pra você.

Um abraço e bons estudos.