[英]Problems using Mocha with Webpack and Typescript
使用標准的.setup.js
:
require('babel-register')();
var jsdom = require('jsdom').jsdom;
var 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'
};
documentRef = document;
和測試台:
import * as React from 'react';
import { expect } from 'chai';
import { mount, shallow } from 'enzyme';
import * as mocha from 'mocha';
class Woof extends React.Component<{},{}> {
render() {
return <p>woof</p>;
}
}
describe('<Woof />', () => {
it('passes sanity check', () => {
const wrapper = mount(<Woof />);
expect(true).to.equal(true);
});
});
Mocha無法運行webpack捆綁包,並出現“ TypeError:無法讀取未定義的屬性'crypto'”錯誤。 我正在使用所有涉及軟件包的最新版本。 有人知道對此有任何解決方案嗎?
提前致謝!
經過一些實驗后,實現此工作的一種方法是指示webpack
到目標node
並從包中排除node_modules
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.