【问题标题】:How to test a component using Enzyme which loads based on Process.env variable如何使用基于 Process.env 变量加载的 Enzyme 测试组件
【发布时间】:2018-02-16 15:10:45
【问题描述】:

我有一个基于 Process.env 变量加载的 DIV,任何人都可以为我指明如何测试本节的方向吗?

{ process.env.STYLE === 'RNR' &&
            <div className="price-option">
            <span>$ <input type="text" ref="minInput" placeholder="Min" defaultValue={minValue} /></span>
            <span>{i18n.l('to ')} $ <input type="text" ref="maxInput" defaultValue={maxValue} placeholder="Max" /></span>
            <button onClick = {this.filterPrice.bind(this)} ref={(node) => { this.minMaxfilter = node }} >{i18n.l('Go')}</button>
            </div>
        }

【问题讨论】:

    标签: reactjs mocha.js chai enzyme


    【解决方案1】:

    一种简单的方法就是将process.env 变量设置为您要测试的值。请记住在拆卸时将变量恢复为原始值

    const originalSTYLE = process.env.STYLE;
    process.env.STYLE = 'tested-value';
    
    // your test
    
    // Reset original value
    process.env.STYLE = originalSTYLE;
    

    【讨论】:

      猜你喜欢
      • 2018-04-28
      • 2021-04-21
      • 2017-01-01
      • 2021-06-11
      • 1970-01-01
      • 2017-04-13
      • 1970-01-01
      • 2017-09-13
      • 2019-08-11
      相关资源
      最近更新 更多