All Questions
9,237
questions
0
votes
0
answers
12
views
Mock static method of object in react jest
I want to mock a static method defined outside a component.
Here is my component:
import Authenticate from '/api/Authenticate';
export default class MyComponent extends React.Component {
render() {
...
-1
votes
0
answers
13
views
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax,
This is the error i am getting:
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 ...
0
votes
0
answers
15
views
onClick event not being handled/fired while testing - Custom component with Lit Element using React Wrapper
I have this below component that is a Header Component with an AccessBar and an Icon Component with certain props. All the custom components are actually Lit Element components (uses shadowDOM) from a ...
-2
votes
0
answers
19
views
How can I implement Jest with React useContext? [closed]
I am trying to create a simple snapshot test of a component that implements useContext. I have wrapped the component with the ContextProvider but I am still getting the following error:
TypeError: ...
-1
votes
0
answers
10
views
Rollup/Yalc/Babel: "SyntaxError: Cannot use import statement outside a module"
Currently in the process of splitting up a large project into smaller npm packages. for local dev we are using yalc, for the npm package projects we are using Rollup.js with a separate .babelrc config ...
0
votes
1
answer
11
views
How to mock recoil custom hook
Custom hook:
export const usersState = atom({
key: 'usersState',
default: [],
});
export const useUsersList = () => {
return useRecoilValue(usersState);
};
React component:
export const ...
-1
votes
1
answer
17
views
Getting error in Component testing - Jest & react-native testing library
Getting error when using the render method to test component
`Trying to detect host component names triggered the following error:
Unexpected token 'export'
There seems to be an issue with your ...
0
votes
0
answers
28
views
jest.config.ts file not working with react-scripts test
I am new to Jest and struggling to setup in my React TypeScript Web app. I want to keep all my Jest configuration details in a single file jest.config.ts. I keep getting an unknown long list of errors:...
-1
votes
2
answers
24
views
Jest react test : API call failed TypeError: Cannot read properties of undefined (reading 'json')
I am going to test the components below through the jest and react test library.
I want to test if the API is called normally when I press the button, So I made the API calling part mock.
However, ...
1
vote
1
answer
38
views
Jest error: Jest encountered an unexpected token - query-string import
I'm getting the following:
babel.config.json:
{
"presets": [
["@babel/preset-env", { "targets": { "esmodules": true } }],
["@babel/preset-react&...
0
votes
0
answers
14
views
How to write test cases for file input using jest?
I am trying to write test cases for input type file but I am getting empty file like this e.g. File {}
const PortNumberStep1 = ({
state,
phoneTypeData,
phoneNumberProviderData,
getValues,
...
-2
votes
0
answers
28
views
What error is this: "Jest encountered an unexpected token"? It came from "isPortReachable" import of my code to be tested
Im trying to do Jest testing for all my domain/service/business logic of my web app.
One of the import was isPortReachable, and Conf, but apparently every file with this import would fail the test ...
0
votes
0
answers
20
views
Unable to mock JSEncrypt 3rd party library in jest
encryptPassword.js
import { JSEncrypt } from 'jsencrypt';
export const encryptPassword = (pwd, rsaPublicKey) => {
let retVal = pwd;
try {
const encrypt = new JSEncrypt();
encrypt....
0
votes
0
answers
23
views
How mock Blob using jest and jest-fetch-mock
I am using React, and RTK Query and trying to write tests, checking correct downloading files, using jest and jest-fetch-mock.
test('should download correct file', async () => {
const text = '<...
-1
votes
0
answers
17
views
How to make import with "?" sign work with react testing library and jest
I have react/nextjs/MUI app.
I need to have 2 different independent instances of the same module using the same codebase and for this purpose I use the cool hack that works fine:
in all files
where I ...