나는 일렉트론을 사용하여 반응 프로젝트를 설정하려고하고 있으며, 테스트 프레임 워크로 모카를 구성하기 시작했다.모카를 이용한 반응 테스트에 대한 불변의 위반
"test": "mocha -w --require babel-core/register --require ignore-styles ./app/test/helpers/browser.js ./app/**/*.spec.js --colors --growl"
내 사양 파일이 단순한를 설명하고 1 내가 시도하고 구성 요소를 반응 포함 할 때 문제가 발생 1.
에 해당된다는 주장했습니다
모든 내가 실행하면 잘 : 그는 내가 얕은가 마운트도 전에, 내 테스트에 포함되어
import style from './app.scss';
import React from 'react';
import {render} from 'react-dom';
export default class App extends React.Component {
render() {
return (
<div>
<h1 className={style.title}> Hello World </h1>
</div>
)
}
}
render(<App/>, document.getElementById('app'));
, 내가 얻을 :
Invariant Violation : _registerComponent (...) : 대상 컨테이너가 DOM 요소가 아닙니다.
나는 jsdom을 사용하고 같은 브라우저의 ENV를 설정 해요 :
import { jsdom } from 'jsdom'
const exposedProperties = ['window', 'navigator', 'document'];
global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
exposedProperties.push(property);
global[property] = document.defaultView[property];
}
});
global.navigator = {
userAgent: 'node.js'
};