I am updating my code from the now deprecated react/addons package to the react-addon-test-utils package. I use jsdom and inject a document and window element, as shown below.
import jsdom from 'jsdom';
import chai from 'chai';
import chaiImmutable from 'chai-immutable';
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>');
const win = doc.defaultView;
global.document = doc;
global.window = win;
Object.keys(window).forEach((key) => {
if (!(key in global)) {
global[key] = window[key];
}
});
chai.use(chaiImmutable);
And here is my unit test.
import {expect} from 'chai';
import ErrorBlock from '../src/Controls/ErrorBlock';
import React from 'react-addons-test-utils';
const {renderIntoDocument, scryRenderedDOMComponentsWithClass, Simulate}
= React;
describe('ErrorBlock', () => {
it('renders properly', () => {
const id = 'test';
const message = 'my message';
const alertStyle = "alert-danger";
const component = renderIntoDocument(
<ErrorBlock id={id} message={message} alertStyle={alertStyle} />
);
const spanEntry = scryRenderedDOMComponentsWithClass(component, id + 'AlertMessage');
expect (spanEntry.length).to.equal(1);
});
});
I am in the process of getting unit testing setup for a React UI module for use on some projects. However, when I switch over to the new react-addons-test-utils package, I get the following error:
TypeError: _reactAddonsTestUtils2.default.createElement is not a function
This error occurs on the line where I define my component.
Why am I getting this error ONLY when using the new package?
Aucun commentaire:
Enregistrer un commentaire