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.

0
votes
0answers
6 views

How to test rxjs ajax call with jest?

I have a container component where I'm fetching the data via ajax operator from rxjs const data = ajax(someUrl).pipe(map(r => r.response)); And in my componentDidMount I have data.subscribe((...
0
votes
0answers
4 views

Testing a fs library function with Jest/Typescript

I am trying to test a library function that I have written (it works in my code) but cannot get the testing with the mock of the fs to work. I have a series of functions for working with the OS ...
0
votes
0answers
17 views

How to test components with DOM API in React

I have a React component which used canvas API. When I test it by jest & react-test-renderer, there is an error occurred TypeError: Cannot read property 'getContext' of null. And here is a very ...
0
votes
0answers
10 views

Apollo Query testing won't pass loading

I'm testing an Apollo Graph Query in my React project using Jest and Enzyme. I have setup a mock of the child component. When running the test I get: Method “props” is only meant to be run on a ...
0
votes
1answer
23 views

Jest test fail “Window is not defined”

In my react application I have configure jest and enzyme for snapshot testing. One of my test failed with error: ReferenceError { message: 'window is not defined', } I'm using window(global ...
1
vote
1answer
15 views

why is jest not required?

I have a react app and I don't know why I don't need to require the jest module. import Task from './Task'; describe('class Task', () => { it('inProgress()', () => { var t = new Task("...
0
votes
1answer
17 views

React - Jest Mock an inner component

I have a component that has a child component. This child component has some rules to display its children content, and I want to mock it to display the content regardless its rules. import ...
0
votes
0answers
8 views

Spy on a method passed into a mocked node module

I am building a client that will wrap the SignalR library: export class RealTimeCommunicator { /** SignalR hub connection */ private hubConnection: HubConnection | null = null; private ...
0
votes
1answer
16 views

How to test websockets (gateways) containing exception filters in e2e testing

Problem Exception filters does not seem to be used at all when doing E2E testing on a gateway Code some-gateway.e2e-spec.ts import { INestApplication } from '@nestjs/common'; import { Test } from '...
3
votes
1answer
23 views

Using jest-each for dynamic data testing

I working on React credit card input component. I need to test credit card numbers by brand type using jest-each. Existing code works but need to replace it with jest-each for dynamic data testing. ...
2
votes
0answers
32 views

Unit testing a formik component with jest/enzyme

I've put together a pretty basic contact form that works just fine. However I now need to start writing my unit tests and I've run into a load of problems (like I literally have only managed to get a ...
1
vote
0answers
27 views

Jest: mock RxJs pipe

How to mock more complex RxJs behavior (in a context of NgRx)? Given a simple component (SomeComponent): export class SomeComponent implements OnInit { foo$: Observable<any>; bar$: ...
0
votes
2answers
18 views

Jest/Mocha + TypeScript: Jest/Mocha tries to read JS dependencies and fails - “unexpected token import”

So, I'm testing a TypeScript file with Mocha, I access a dependency in the file via import, and the function to test is in the same file, like below: import { Foo } from 'foo-library'; // I'm trying ...
0
votes
0answers
13 views

How to configure jest to be able to use es2015 in webstorm?

I have created a react project using create-react-app. I can execute unit tests in the terminal using "yarn test". I want to run tests using the run options in webstorm. However if run it, I got ...
0
votes
0answers
11 views

Jest calculates coverage in very different ways on the same file

Given: JSX file with React Component (69 lines, 61 of them are non-empty) and Jest spec file for it. If I generate coverage report, I'm getting coverage in LoC 4 of 8. In JSON report all method names ...
1
vote
0answers
19 views

Testing Typescript with Jest in Visual Studio code does not show proper source code lines

I have tried to get Jest to run properly in Visual Studio code. While I can debug Typescript without an issue, I am unable to get to the proper lines on included functions with Jest. I have a test ...
0
votes
1answer
40 views

Button click event callback not being called — jest/enzyme

I have the following test that tests calling of a callback method on button click with the argument passed as the value of text input of my Estimate component. Test: let obj let fn describe('...
0
votes
1answer
30 views

Testing an isolated function of a component in React Jest

I am fairly new to Jest and Enzyme and I stumbled a cross a problem: I have a Component which renders Children and also calls a method of those children. I achieve that by using refs. I call these ...
0
votes
1answer
28 views

Use variable expressions in test.each Jest

Below is my code snippet: describe('Upper Describe,()=>{ let value; beforeEach(()=>{ value=require('testModule').value; }); it.each([ `${value}`, ])('test something',(value)=&...
0
votes
1answer
16 views

Unit testing with Jest without module.exports

I have a script that holds a single const variable which holds all of my logic, kind-of like Moment.js. I want to test out functions that go out with this script with Jest. I can't use module....
1
vote
0answers
21 views

supertest mock with nock.back record mode not working

I have a nodejs service that when calling it's endpoint, does an http call to a service B. I'm adding an acceptance test to my service to test the integration. Using nock.back in dryrun mode works ...
0
votes
0answers
6 views

Implementing Jest in Rails app SyntaxError: Unexpected identifier config/webpack/test.js FAIL

I am switching my tests from Karma in my rails/react app to Jest. By following tutorial here I got a few errors I have solved and make PASS one dummy test spec/javascript/sum.test.js test('1 + 1 ...
1
vote
1answer
16 views

Using Jest+Enzyme+React does not point the right line on error

When I have an error in my test (let's say I use a function that does not exists with Jest), Jest does not point the right line for error. So If I use a function that does not exists: expect(wrapper....
1
vote
1answer
17 views

Proper method to implement Jest tests in Jenkins build

We're using Jest to perform our React.js unit tests (on the frontend) of our Node.js app which runs in a docker container. We have set up a Pipeline in Jenkins but I'm unsure of the best way (or ...
0
votes
1answer
31 views

Integration testing with Nuxt and Jest

I wish to render a page using Nuxt's renderAndGetWindow in order to test the values returned by my API. Here's how I do it: // Nuxt instance let nuxt = null; // Our page to test let homePage = null; ...
1
vote
0answers
17 views

How to test a unhandledRejection / uncaughtException handler with jest

I have handlers for unhandledRejections and uncaughtExceptions: bin.js ['unhandledRejection', 'uncaughtException'].forEach(event => { process.on(event, err => logger.error(err)); }); Now I ...
0
votes
1answer
36 views

Jest tests crashing due to ES6/Es.next Syntax

I'm trying to do some simple snapshot testing with jest and enzyme—moving to react-testing-library—for some react components that I am building. When I run my tests the output contains a number of ...
1
vote
1answer
29 views

Jest/Enzyme SVG Sprites Unexpected Token <

I am having a problem creating a snapshot test with Jest and Enzyme on a component using SVG sprites. I am using the package svg-sprite-loader: https://github.com/kisenka/svg-sprite-loader Here is ...
0
votes
1answer
33 views

How to test callback argument react native

I have a react native component that looks like: export class Estimate extends PureComponent { setRef = (ref) => { this.estimateForm = ref } render () { const { onPress } = ...
1
vote
0answers
30 views

how to mock saga generator function with jest and enzyme

I'm trying to test if my generator function is called when I call dispatch function. I'm doing something like: in my saga.js: import { takeLatest } from 'redux-saga/effects' import { ...
1
vote
0answers
39 views

NodeJS write to stdin in jest tests

I have a command-line app that reads user input from stdin: const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, }); rl.on('line', (line) => { ...
1
vote
0answers
15 views

Black box testing a Node process making external requests with Jest

I am currently working on a project where we have a backend process running (with process.env.NODE_ENV = 'test') and then test the backend by running a Jest instance which makes calls to the backend ...
1
vote
2answers
17 views

Run specific jest project

I'm setting up a lerna monorepo with jest, I'm using jest's projects like so: projects: ['<rootDir>/packages/*']. Running tests work as expected, however, I'm not sure how can I run a specific ...
2
votes
1answer
42 views

Jest mock async function from default import

I'm trying to mock an async function that is exported as a default export but all I get is TypeError: Cannot read property 'then' of undefined What I'm trying to mock is config.js: const ...
1
vote
0answers
34 views

Jest render test crashes due to failed fetch post

Here is the code I am trying to test: onDrop(acceptedFiles) { const upload = (file) => { fetch(url, { method: 'POST', headers: this.props.headers, body: file, }).then((...
1
vote
1answer
21 views

Unit-testing React Components using Context Consumers

I used to have component that looked like this: class Foo extends React.Component { render() { return ( <div className="Foo"> <div id="user">Bar<...
1
vote
2answers
46 views

React component testing using Jest

Hi I am new to Jest and Java Script. I want to perform a test over one of my components. I want to check that the Admin see the sentence: "Please select a user to show his/her donations:" My ...
3
votes
1answer
38 views

testing fails with Jest

I have got a code for which I have to perform tests on. After installing Jest and using it with enzyme for testing different components, now I have to check that only Authorized tenants can access my ...
0
votes
1answer
41 views

How to do Integration tests NodeJS + Firebase Admin?

I'm trying to write some integration tests on NodeJS with Firebase (firebase-admin, with the test library jest and supertest), and some tests are failing randomly when I run all my tests. Separately, ...
2
votes
1answer
35 views

Cannot access previous DOM elements after recent update in Jest/Enzyme unit tests

I'm using Jest with Enzyme to unit test my application. I used to test it this way: const textFieldWrapper= shallow(<TextField label="Standard" />); expect(textFieldWrapper.find('input').length)...
0
votes
1answer
15 views

Vue.js test:unit with test-utils and Jest : Nested component -Is it possible to mock the $emit(function) from child component?

Given nested components the Heading.vue component {{ $t("lang.views.home.heading.btn__listen") }} play_arrow ...
1
vote
1answer
27 views

Unexpected behaviour testing React component after delay with Jest/Enzyme

I have a pretty basic React component that displays a sequence of dots for when something is loading, by default it displays up to 3 dots and the dots increment on an interval set within a ...
1
vote
0answers
14 views

How to update attrs to component in unit test?

I have a component like this text-box.vue <template> <3rd-party-text v-bind="$attrs" /> </template> using it like ... <text-box :value="my value" /> ... Now the issue ...
0
votes
2answers
34 views

How to test a Promise callback inside a non-Promise function?

I have a function that have promise function called inside. But itself doesn't return the promise. const toBeTestedFunc = () => { const promise = promiseFunc() .then(() =&...
1
vote
1answer
44 views

How to test a public async function inside Class using Jest in a ReactJS/Typescript app

Property 'getUsersTotalPayout` does not exist on type typeof PayoutApi My Class: import { bind } from 'decko'; import BaseApi from './Base'; import * as NS from './types'; class PayoutApi extends ...
3
votes
1answer
22 views

Jest test: Cannot find module '../Link.react' from 'Link.react.js'

I am trying to setup jest test following https://jestjs.io/docs/en/tutorial-react I have installed the jest related dependencies, created __test__/link.react.test.js and Link.react.js. Following is my ...
0
votes
0answers
47 views

How to test javascript class using jest?

trying to test class using jest its throwing declaration exception , what would be correct approach to test class in below scenario and test promise chain? main.ts export class ModuleExecutor { ...
0
votes
1answer
55 views

Babel7 Jest unexpected token export

I am having issues in running jest tests in my project with Babel7. Tests used to transpile perfectly with babel6. It also compiles perfectly with webpack with Babel7 but fails to run tests with jest ...
0
votes
1answer
29 views

How do you test components that are wrapped with multiple higher order components?

import React from 'react' import sinon from 'sinon' import { mount } from 'enzyme' import configureStore from 'redux-mock-store' import FileListEditable from './index.js' import {shallow} from 'enzyme'...
4
votes
0answers
40 views

Shallow test function as child components

I have added a component which is using function as a child. I had shallow enzyme tests for this component which stopped working. How can I shallow test a component which is using function as a child?...