在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/網(wǎng)絡安全/ 在 Karma + jasmine 中 enzyme 的 setup 文件應該寫

在 Karma + jasmine 中 enzyme 的 setup 文件應該寫在什么地方

昨天將項目更新到 React v16.0 ,但是 CI 構建出現(xiàn)如下問題:

 Error:
              Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none. To
              configure an adapter, you should call `Enzyme.configure({ adapter: new Adapter() })`
              before using any of Enzyme's top level APIs, where `Adapter` is the adapter
              corresponding to the library currently being tested. For example:
              import Adapter from 'enzyme-adapter-react-15';
              To find out more about this, see http://airbnb.io/enzyme/docs/installation/index.html

查閱文檔發(fā)現(xiàn) Enzyme 3.0 Api 發(fā)生變化

按照官方的說法,需要在 setup file 中添加如下代碼。

// http://airbnb.io/enzyme/docs/installation/react-16.html
// setup file
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });

那么問題來了,應該添加到什么地方?

嘗試添加到每個測試文件前,沒有成功
嘗試添加到 `karma.conf.js` 的 `files: []` 中,也沒有成功。
回答
編輯回答
熊出沒

雖然沒有在網(wǎng)上查到具體setup file具體作用,但是在github中通過下載一下別人的測試包會發(fā)現(xiàn),setup.js多是包含了執(zhí)行測試腳本前的準備工作

例如: mocha --compilers js:babel-core/register --require ./test/setup.js
setup.js中的代碼為
`import jsdom from 'jsdom';

if (typeof document === 'undefined') {
global.document = jsdom.jsdom('<!doctype html><html><body></body></html>');
global.window = document.defaultView;
global.navigator = global.window.navigator;
}
`
以上均是個人猜測,希望可以幫到你

2018年3月16日 01:19