Tôi đang sử dụng Mocha, Chai, Karma, Sinon, Webpack cho các bài kiểm tra Đơn vị.Làm thế nào để kiểm tra đơn vị React-Redux kết nối các thành phần?
Tôi đã nhấp vào liên kết này để định cấu hình môi trường thử nghiệm của mình cho Mã phản hồi-Redux.
tôi thành công có thể kiểm tra hành động, giảm thiểu tôi mã javascript, nhưng khi nói đến việc kiểm tra các thành phần của tôi nó luôn ném một số lỗi.
import React from 'react';
import TestUtils from 'react/lib/ReactTestUtils'; //I like using the Test Utils, but you can just use the DOM API instead.
import chai from 'chai';
// import sinon from 'sinon';
import spies from 'chai-spies';
chai.use(spies);
let should = chai.should()
, expect = chai.expect;
import { PhoneVerification } from '../PhoneVerification';
let fakeStore = {
'isFetching': false,
'usernameSettings': {
'errors': {},
'username': 'sahil',
'isEditable': false
},
'emailSettings': {
'email': '[email protected]',
'isEmailVerified': false,
'isEditable': false
},
'passwordSettings': {
'errors': {},
'password': 'showsomestarz',
'isEditable': false
},
'phoneSettings': {
'isEditable': false,
'errors': {},
'otp': null,
'isOTPSent': false,
'isOTPReSent': false,
'isShowMissedCallNumber': false,
'isShowMissedCallVerificationLink': false,
'missedCallNumber': null,
'timeLeftToVerify': null,
'_verifiedNumber': null,
'timers': [],
'phone': '',
'isPhoneVerified': false
}
}
function setup() {
console.log(PhoneVerification);
// PhoneVerification.componentDidMount = chai.spy();
let output = TestUtils.renderIntoDocument(<PhoneVerification {...fakeStore}/>);
return {
output
}
}
describe('PhoneVerificationComponent',() => {
it('should render properly', (done) => {
const { output } = setup();
expect(PhoneVerification.prototype.componentDidMount).to.have.been.called;
done();
})
});
Lỗi sau đây đi kèm với mã trên.
FAILED TESTS:
PhoneVerificationComponent
✖ should render properly
Chrome 48.0.2564 (Mac OS X 10.11.3)
Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Đã cố gắng chuyển từ gián điệp sin sang gián điệp.
Tôi nên kiểm tra các thành phần kết nối phản ứng-Redux của tôi như thế nào (Các thành phần thông minh)?
Bạn đang xuất thành phần của mình như thế nào? Bạn đang sử dụng xuất có tên hoặc chỉ mặc định xuất? 'Import {PhoneVerification} from ' ../ PhoneVerification '; 'là dòng vi phạm của bạn, khi bạn thực hiện việc này, bạn sẽ không nhận được thông báo lỗi tương tự nếu bạn không thực hiện xuất tên được đặt tên –
Tôi đang sử dụng Xuất tên đã đặt tên – Ayushya
Tôi cũng có cài đặt tương tự và nhận được thông báo lỗi tương tự – FujiRoyale