Questions tagged [jestjs]
Jest is a JavaScript unit testing framework made by Facebook based on Jasmine and provides automated mock creation and a jsdom environment. It's often used for testing React components.
jestjs
23,095
questions
-1
votes
0
answers
10
views
How to spy on public field with Jest+jest-auto-spies
I've this Angular service that I'm trying to mock:
@Injectable({
providedIn: 'root',
})
export class NotificationsService {
private _notifications = new Subject<Notification>();
public ...
0
votes
0
answers
6
views
How can i mock knex transaction
i have unit test for function sync in these code but i get error like below i cant mock the function knex.transaction() for trx. i have tried some another way but i usually get trx is not the fuction ...
0
votes
1
answer
10
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 ...
0
votes
0
answers
12
views
It is impossible to change the value of a MUI DatePicker or MUI TimePicker with react-testing-library?
I have this component that uses Material UI datepicker and timepicker.
function MyComponent() {
const [dateFilter, setDateFilter] = useState(moment());
const [timeFilter, setTimeFilter] = ...
-1
votes
0
answers
19
views
RollUp/Yalc/Babel/Jest Cannot use Import statement outside of a module
So I am in the process of splitting down large VS projects in to separate modules (built with Rollup, published to an Azure artifacts repository and locally linked via Yalc), and I am running in to an ...
-1
votes
1
answer
14
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
20
views
mocking createAsyncThunk exhibits odd behavior
I am trying to mock createAsyncThunk from reduxjs/toolkit as follows:
// mock.ts file
import { createAction } from "@reduxjs/toolkit";
export const mockedToolkit: unknown = {
...jest....
0
votes
0
answers
24
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
21
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
18
views
How can I mock prompt-sync module using jest
I have this method promptPlayer in the class Player which job is to return to the player the index of an empty slot. But inside the method I am running prompt from the prompt-sync module of JS. Cant ...
0
votes
0
answers
16
views
Why are my NestJS Guards not included in Jest code coverage?
I have written unit tests for my Nest Guards, and then run just fine and pass, but when I check my code coverage they are not included in that! You can see in my console output the *.guard.ts files ...
0
votes
0
answers
33
views
Nest can't resolve dependencies of the FollowService Please make sure RedisService at index [2] is available in the RootTestModule context. how to fix
FAIL follow/follow.resolver.spec.ts ● FollowResolver › should be
defined
Nest can't resolve dependencies of the FollowService (aService, bService, ?). Please make sure that the argument
RedisService ...
1
vote
1
answer
31
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&...
-1
votes
0
answers
24
views
How to mock my util DynamoDB GetItemCommand implementation?
I've got code that uses GetItemCommand to get data from my DynamoDb instance, however I'm not entirely sure how I go about testing my function that uses it.
I don't want to test the GetItemCommand ...
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,
...