Botframework-webchat causing Jest tests to fail in Create React App #5379
Labels
Bot Services
Required for internal Azure reporting. Do not delete. Do not change color.
customer-reported
Required for internal Azure reporting. Do not delete.
question
Further information is requested. Stack Overflow candidate
I have a question
Hello,
TL;DR How do I write a Jest test for a component that contains ReactWebChat?
I am trying to write a test file for my website and the ReactWebChat component consistently causes the test to fail with the same error message every time, always indicating that the issue lies somewhere in the botframework-webchat package.
My real implementation has a lot more going on in it - auth flows, handling data, styles, etc - so I stripped all of that away to the essence of the problem detailed in the steps below. I receive the same failure message regardless of if I use a real directLine with a real token or if I use the directLine with a fake token, like below.
I am using Create-React-App (CRA) and its subsequent dependencies (i.e. Jest) in addition with botframework-webchat. That's it.
Steps to recreate:
npx create-react-app webchat-test
cd webchat-test
npm install botframework-webchat
code package.json
Observe the addition of
"type": "module",
- everything else is OOTB from CRA and installing the botframework-webchat pkgSave
cd src
code index.js
Observe the adjustment on the
import App
statement, now including the file extension.js
- everything else is CRA OOTBSave
code App.js
Observe the removal of most OOTB pieces here, substituted with the WebChat component we will be making shortly
Save
mkdir WebChat
cd WebChat
touch WebChat.jsx
code WebChat.jsx
Save
mkdir __test__
cd __test__
touch WebChat.test.jsx
Save
At this point, feel free to remove the css files, the App.test.js file, and any other unused files
npm run build
npm run test
Observe the test fails:
I'm at a loss of what I should do next, I have been entirely unsuccessful in overcoming this error message. I have tried ejecting CRA, I have tried the suggestions as they are explained in the error message, I have tried without including
"type": "module"
in thepackage.json
file, I have tried using Typescript and using different jest presets like ts-jest, I have tried to include the file causing the issue/node_modules/mime/dist/src/index.js
as part of thetransformignorepatterns
in jest, several other small tweaks and attempts have been made over the past few days and I cannot get this error message to budge.Does anyone know what I am doing wrong?
Thank you,
Sean
The text was updated successfully, but these errors were encountered: