嘿,我一直在配置karma + jasmine +酶,开始在我的项目的单元测试中工作,然后在exec我的第一次测试我得到了这个错误
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
然后这是我的测试代码:
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);
});
});
我也在使用: 茉莉:2.5.3 酶:2.7.1
答案 0 :(得分:0)
您需要创建类
的设置实例beforeEach(() => {
wrapper = new setup();
});
答案 1 :(得分:0)
我已经找到了问题的答案,我只是删除了jasmine导入器并在名为.eslintrc.json
的{{1}}等于expect
true
中添加了一个全局变量