【问题标题】:How to add property to mocked module jest?如何将属性添加到模拟模块笑话?
【发布时间】:2018-03-10 03:16:16
【问题描述】:

我有一个由 webpack 在构建时生成的模块,称为 config。

// webpack.config.js
let devConfig = {url: 'https://localhost'}
...
externals: {
    'config': JSON.stringify(devConfig),
},

我导入并喜欢它;

import config from 'config'
console.log(config.url)

如何模拟这个模块,并在测试期间提供 url?

我已经尝试过关注。它使配置对象可用但不是 url。

// __mocks__/config.js
jest.mock('config', ()=>({url: 'https://localhost'}), {virtual: true})

如何将 url 属性添加到模拟模块?

谢谢。


注意:我需要 url,因为我在使用 nock 时需要它。

【问题讨论】:

  • 财产 == 财产?

标签: javascript unit-testing jestjs


【解决方案1】:

在这里;

看起来有别的东西在阻止我。

jest.mock("Config", ()=> ({url: 'https://localhost'}), {virtual: true});

【讨论】:

    猜你喜欢
    • 2018-12-31
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 2021-07-03
    • 1970-01-01
    • 2017-03-27
    相关资源
    最近更新 更多