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,099
questions
0
votes
0
answers
11
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
6
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
17
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
19
views
Jest error: Jest encountered an unexpected token - queryString import
I'm getting the following:
babel.config.json:
{
"presets": [
["@babel/preset-env", { "targets": { "esmodules": true } }],
["@babel/preset-react&...
-1
votes
0
answers
19
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
13
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
14
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
16
views
Need to know jest dom setup in plain vanilla javascript
i created an todo app in vanilla javascript now i needed to test that using jest but the thing jest-environment is not working on that. i need proper procedure to setup get done
package.json
{
"...
0
votes
0
answers
13
views
NestJS & Jest: The presence of jest.config.ts causes "strange behavior" during build
I have a Nestjs service inside my monorepo project with the following structure:
/
- package.json
- packages/
- - frontend/
- - backend/
- - backend/package.json
backend is the nestjs service, ...
0
votes
0
answers
14
views
How to change the value of a MUI DatePicker or TimePicker in Jest/react-testing-library?
I have a component that uses the Material UI datepicker and timepicker.
function MyComponent() {
const [dateFilter, setDateFilter] = useState(moment());
const [timeFilter, setTimeFilter] = ...
-1
votes
1
answer
16
views
What is "Argument of type <mock parameters> is not assignable to parameter of type 'never'" in Jest?
I took a bunch of examples online and ChatGPT code to do my testing. I ended up with some red squiggly lines under the parameters mockResolvedValue with the error:
Argument of type '{ email: string; }'...
0
votes
0
answers
14
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
1
answer
26
views
Jest toHaveBeenCalled() doesn't work for me
I am mocking up some function:
export const natsWrapper = {
client: {
publish: jest
.fn()
.mockImplementation(
(subject: string, data: string, callback: () => void) =>...
0
votes
0
answers
7
views
Test wp.data with Jest in Block Plugin
I am trying to get my head around testing my Wordpress Block Plugin with Jest. I am specifically struggling how to mock calls to wp.data.
See the following function:
import apiFetch from '@wordpress/...
0
votes
0
answers
22
views
How to test react-native-auth0 library with detox?
I can't find a way anywhere that explains how to properly mock auth0 requests in React Native.
Several questions made on detox GitHub says that its not their responsibility to explain how to mock ...