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']}' –