2
原料裝載有使用的WebPack原料裝載機e.g與SVG的加載內嵌一些組件...我如何忽略測試的WebPack
import React, { Component } from 'react'
import svg from '!raw!../assets/images/logo.svg'
export default class Logo extends Component {
render() {
return (<a href={this.props.url} dangerouslySetInnerHTML={{__html: svg}} />)
}
}
當試圖測試使用磁帶這些組件的服務器端,他們摔倒。如果我有css模塊包含,這是沒有問題的,我可以使用css-modules-require-hook但svg的將無法正常工作。所以我真的需要一個raw loader需要鉤子或類似的東西。
require('babel-register');
require('css-modules-require-hook/preset');
/* tests after this can import components with css includes */
我嘗試過使用isomorphic-ensure,但這沒有奏效。如果你不使用的WebPack爲你的測試,那麼你可以使用ignore-styles module
Cannot find module '!raw!../assets/images/
你正在通過webpack運行你的測試嗎?如果沒有,你可以將'import'推到模塊外面並注入它(作爲道具傳遞)?如果這不適合你,你可以考慮像[rewire](https://github.com/jhnns/rewire)? –
不,我沒有測試的webpack配置,只是'require('babel-register');'然後'require('isomorphic-ensure')'然後是我的組件,動作,reducer測試列表。例如'require('./ components/Logo.spec.js');' –
在我的webpack.config中的實際應用程序我有以下的加載器svg's:'{test:/\.svg$/,loaders:[' react-svgdom','svgo']}' –