简体   繁体   English

React Enzyme浅层渲染中的transform-class-properties插件

[英]transform-class-properties plugin in React Enzyme shallow rendering

Enabled transform-class-properties plugin webpack module exports, which is helping me to have class which is a registered word in javascript to be used normally in my html code and transpilation step using the plugin takes on the heavy lifting. 启用了transform-class-properties插件的webpack模块导出,这帮助我拥有了classclass是javascript中的注册词,通常在我的html代码中使用,使用该插件的翻译步骤承担了沉重的负担。

I'm using enzyme for testing components now I have issue where in I have my component like this. 我现在正在使用enzyme来测试组件,但是我遇到这样的组件存在问题。

export default class Settings extends React.Component {
    render() {
        return (
            <div class='something'>Settings</div>
            );
    }
}

If I want to test in my unit test if I have any something class in my Component it fails always. 如果我想在我的单元测试来测试,如果我有任何something类在我的组件,但是总是失败。

export default class Settings extends React.Component {
    render() {
        return (
            <div className='something'>Settings</div>
            );
    }
}

But if I do the above transformation myself, I have UT passing. 但是,如果我自己进行上述转换,则会有UT通过。

How can I do the transformation step to kick in before unit testing too. 我如何也可以在单元测试之前执行转换步骤。 I'm using npm script test like this "test": "mocha -w ./test/**/*.js --compilers js:babel-core/register --reporter spec", 我正在使用像这样的"test": "mocha -w ./test/**/*.js --compilers js:babel-core/register --reporter spec",这样的npm脚本测试"test": "mocha -w ./test/**/*.js --compilers js:babel-core/register --reporter spec",

我的坏-解决方案在于.bablerc使用另一个stackoverflow线程解决了该问题Mocha为ES6对象散布运算符抛出了意外的令牌错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM