Closed PriyaNspire closed 1 year ago
Are you using Next.js? Your issue may be the same as https://github.com/pusher/push-notifications-web/issues/78.
The solution for them was https://github.com/pusher/push-notifications-web/issues/78#issuecomment-825348735
Thanks @benjamin-tang-pusher for response. I am not using Next.js. Above mentioned issue raised in React.
This issue show when I execute npm test comment in the terminal.
I get the same error with npm test
, but npm start
works fine (I can also go on to call start()).
I may have encountered this issue with the jest tester in the past. Let me see if I can dig up past cases of this.
Thanks @benjamin-tang-pusher
Please tell me know, If you get solution of this error.
I got past this error message by following this StackOverflow, and changing my package.json to this:
"test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!@pusher/push-notifications-web)/\"",
I bumped into another error that doesn't look related:
Pusher Beams does not support this browser version (IndexedDB not supported)
I think Beams with jest needs extra configuration with IndexedDB, but I'm not familiar with these two, and will need to do further investigation. Will let you know what I find.
I used fakeIndexedDB (npm install --save-dev fake-indexeddb
and put import "fake-indexeddb/auto";
in App.test.js) to mock an IndexedDB api for the Beams library to use when run with jest. It goes onto another error message Pusher Beams relies on Service Workers, which only work in secure contexts. Check that your page is being served from localhost/over HTTPS
, so there's more to be done. But I'd say your original error message has been solved by my previous comment.
As for how to run the React test with jest whilst importing Beams, unfortunately I'm not very familiar with jest. Our Beams library expects to run in a web browser environment, which jest by itself won't provide (it just simulates the DOM, and its not an actual headless web browser). Has anyone else managed to get their React tests running with Beams?
After further investigation, I'm going to have to admit that full headless web browser testing is an another topic that you're going to have to ask on their stack overflow https://stackoverflow.com/questions/tagged/jestjs . I don't think many people are using jest with Beams. I will close this GH issue.