如何使用基于Process.ENV变量加载的酶来测试组件



我有一个基于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>
        }

一种简单的方法将包括将process.env变量设置为要测试的值。只需记住将变量恢复为原始值

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

最新更新