Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jest for testing describe is not a function

I have made an app using react and redux, I have some components plus their containers and also an action and a reducer.

I am writing a test for one of my containers using enzyme, chai and jest,

when I try to run my test it gives the following error:

Test suite failed to run

    TypeError: jest_1.describe is not a function

here is my test file:

import * as React from "react";
import { shallow, mount, render } from 'enzyme';
import * as Sinon from "sinon";
import MinPriceContainer from "../../src/containers/SearchForm/containers/MinPriceContainer";
import MaxPriceContainer from "../../src/containers/SearchForm/containers/MaxPriceContainer";
import { expect } from "chai";
import { it, before, describe } from 'jest';

describe('<MinValueInput />', () => {

    let minValueInput;
    beforeEach(() => {
        minValueInput = shallow(<MinPriceContainer />);
    })

//    it('renders component correctly', () => {
//        expect(tabs.find('.MinPriceComponent').exists()).toBe(true);
//    });

    it('cannot have a non numeric value', () => {
        minValueInput = shallow(<MinPriceContainer minimumPriceSelected="i am a string not a number" />);
        expect(minValueInput.find('.error').text()).equal("You cannot use a non numeric value");
    });

    it('cannot have a value less thn zero', () => {
        minValueInput = shallow(<MinPriceContainer minimumPriceSelected={-20} />);
        expect(minValueInput.find('.error').text()).equal("value cannot be less than zero");
    });

    it('it can not have a value greater than maxValue', () => {
        minValueInput = shallow(<MinPriceContainer minimumPriceSelected={99} maximumPriceSelected={80}/>);
        expect(minValueInput.find('.error').text()).equal("value cannot be greater than price");
    });
});

how can I fix this, is this related to my importS? is the test written correctly?

the component that I am testing has a number value called minPrice and it can not be negative and also it should not be more than another component that is called maxPrice, also it should only accepts numbers!

like image 803
S. N Avatar asked Sep 15 '25 01:09

S. N


1 Answers

I take it you're using ts-jest?

replace

import { it, before, describe } from 'jest';

with

import 'jest';

like image 115
Fusselwurm Avatar answered Sep 16 '25 16:09

Fusselwurm