简体   繁体   中英

Undefined is not a constructor Jasmine Enzyme Karma

Hey I have been working in the configuration of karma + jasmine + enzyme to start working in the unit tests of my project, then at exec my first test I got this error

TypeError: undefined is not a constructor (evaluating '(0, _jasmine.expect)(addLoan.length)') in src/app/modules/Login/LoginComponent.spec.js (line 80581) src/app/modules/Login/LoginComponent.spec.js:80581:29 loaded@http://localhost:9876/context.js:151:17

then here is my test code:

 import React from 'react'; import { expect } from 'jasmine'; import { shallow } from 'enzyme'; import ServicerComponent from './LoginComponent'; function setup() { const props = { error: {}, onClick: () => {}, emailOnChange: () => {}, passwordOnChange: () => {}, }; return shallow(<ServicerComponent{...props} />); } describe('<ServicerComponent />', () => { const displayNames = { login: 'login', }; let wrapper; beforeEach(() => { wrapper = setup(); }); it('should have a Login button', () => { const addLoan = wrapper.find({ name: displayNames.login }); expect(addLoan.length).toBe(1); }); }); 

also I am using : jasmine: 2.5.3 enzyme: 2.7.1

You need to create setup instance of the class

beforeEach(() => {
        wrapper = new setup();
    });

我已经找到了问题的答案,我只是删除了jasmine导入器并在.eslintrc.json添加了一个名为expect equal true的全局变量

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM