I get an error with a jest unittest in intellij, which I don't know how to solve.
Simple test:
import React from 'react';
import { render, screen } from '#testing-library/react';
import TestComponenent from "./tests/Testcomponent";
test('test TestComponent', () => {
render(<TestComponenent />);
expect(screen.getByText("test")).toBeInTheDocument();
});
When running this test in IntelliJ, I get the following error:
● Test suite failed to run
TypeError: Class constructor Spec cannot be invoked without 'new'
102 | function createdPatchedSpec(OriginalSpec, registry) {
103 | function PatchedSpec(attrs) {
> 104 | OriginalSpec.apply(this, arguments);
| ^
105 | if (attrs && attrs.id) {
106 | registry[attrs.id] = this;
107 | }
at new PatchedSpec (../../../../Program Files/JetBrains/IntelliJ IDEA 2018.3.4/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-jasmine.js:104:18)
at Object.<anonymous> (src/TestComponent.test.js:5:1)
Versions:
Jest Package : 3.4.1
Nodejs : 12.16.3
Can someone help ?
Solved: I installed the newest Version of IntelliJ.
Related
this is what I have in my test file and have no idea how to fix it was searching everywhere could not find the solution
import { render } from '#testing-library/react';
import { ImageGallery } from '../index';
describe('Swiper has to render', () => {
test('Will Swiper render', () => {
const { asFragment } = render(<ImageGallery />);
expect(asFragment()).toMatchSnapshot();
});
});
having this in my test file
having an error
like that
● Test suite failed to run
Jest encountered an unexpected token
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 syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
SyntaxError: Unexpected token 'export'
1 | /* eslint-disable import/no-unresolved */
2 | import React, { useState, useCallback } from 'react';
> 3 | import { Swiper, SwiperSlide } from 'swiper/react';
| ^
4 | import ImageViewer from 'react-simple-image-viewer';
5 |
6 | import 'swiper/css/bundle';
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
at Object.<anonymous> (src/components/ImageGallery/ImageGallery.js:3:1)
When attempting to run below simple test I get this error
● Test suite failed to run
Cannot spyOn on a primitive value; undefined given
1 | import redis from 'redis';
2 | import redis_mock from 'redis-mock';
> 3 | jest.spyOn(redis, 'createClient').mockImplementation(redis_mock.createClient);
| ^
import redis from 'redis';
import redis_mock from 'redis-mock';
jest.spyOn(redis, 'createClient').mockImplementation(redis_mock.createClient);
describe('something', () => {
it('should pass', () => expect(true).toBeTruthy())
});
Any idea what might be wrong?
I'm trying to launch a Jest test that just happens to import BabylonJS
I'm getting the error below.
export * from "./abstractScene.js";
^^^^^^
SyntaxError: Unexpected token 'export'
> 1 | import * as BABYLON from "#babylonjs/core";
| ^
2 |
3 | describe("Babylong tests2", () => {
4 | test("Should work please", () => {
When I created a CodeSandbox to test, it works GRRRR
https://codesandbox.io/s/jovial-cherry-svdug7?file=/test/babylon.test.ts
When I git clone and npm i && npm run test it fails with the above error
https://github.com/jtwigg/babylonjs-jest/
I'm having a lot of trouble getting traction with testing in a React app (failed with Mocha a million circular errors)
Any help would be appreciated.
I’d appreciate some advice for an error I am running into while running Jest tests.
The code I am running can be found here as I am working on Mozilla’s Devtools:
https://hg.mozilla.org/mozilla-central/file
I have added an import statement to the file devtools/client/debugger/src/components/Editor/SearchBar.js. The file is here:
https://hg.mozilla.org/mozilla-central/file/tip/devtools/client/debugger/src/components/Editor/SearchBar.js
The import statement is:
import { PluralForm } from "devtools/shared/plural-form";
I use this function in my code change. For some reason this is creating errors in the tests "Editor.spec.js" and "SearchBar.spec.js".
Tests can be found here: https://hg.mozilla.org/mozilla-central/file/tip/devtools/client/debugger/src/components/Editor/tests
The error is: Cannot find module 'devtools/shared/plural-form' from 'SearchBar.js'
The function works perfectly fine when I run the code, but Jest is having a hard time resolving the module.
Any help would be appreciated!
I tried adding to modulePaths in the config file.
Cannot find module 'devtools/shared/plural-form' from 'SearchBar.js'
37 | import type SourceEditor from "../../utils/editor/source-editor";
38 |
> 39 | const { PluralForm } = require("devtools/shared/plural-form");
| ^
40 | // import { PluralForm } from "devtools/shared/plural-form";
41 |
42 | function getShortcuts() {
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
at Object.<anonymous> (src/components/Editor/SearchBar.js:39:24)
I am doing jest testing in react native and I have used snackbar in my project. While executing jest i am getting this error.'LENGTH_LONG' is inbuilt variable in snackbar. I am posting where i have used 'LENGTH_LONG' variable and error message. Anyone please help me out
jest "login"
FAIL __tests__\jest\LoginScreen.test.js
● Test suite failed to run
TypeError: Cannot read property 'LENGTH_LONG' of undefined
10 | ScrollView
11 | } from "react-native";
> 12 | import Snackbar from 'react-native-snackbar';
13 |
14 | import { connect } from "react-redux";
15 | import { Button, Text, Divider } from "react-native-elements";
at Object.<anonymous> (node_modules/react-native-snackbar/lib/index.js:1:252)
at Object.<anonymous> (src/screens/login/loginScreen.js:12:26)
at Object.<anonymous> (__tests__/jest/LoginScreen.test.js:3:18)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 2.689s, estimated 4s
Ran all test suites matching /login/i.
Code is
render() {
return (
<View style={styles.mainContainer}>
{this.renderTopLogoContainer()}
{this.renderBottomContainer()}
{this.props.hasError ? Snackbar.show({
title: this.props.error.display_message,
duration: Snackbar.LENGTH_LONG
}) : null}
</View>
);
}
https://github.com/cooperka/react-native-snackbar/tree/master/example
add react-native-snackbar.js file in mocks folder
You have not mentioned whether you are trying to run in ios or android, recently I've seen this issue in ios because I've missed installing the pod.
Try this:
pod install in the ios directory
react-native run-ios
You can also use npm instead of yarn if you prefer.
create a file: 'react-native-snackbar.js' inside the folder 'mocks' with the code
module.exports = {
show: jest.fn()
};