[英]How to add property to mocked module jest?
I have a module which is generated by webpack at build time called config. 我有一个由webpack在构建时生成的模块,称为config。
// webpack.config.js
let devConfig = {url: 'https://localhost'}
...
externals: {
'config': JSON.stringify(devConfig),
},
I import and ise it like; 我导入并喜欢它;
import config from 'config'
console.log(config.url)
How can I mock this module, and give the url during the test? 如何模拟该模块,并在测试过程中提供url?
I've tried following. 我试过跟随。 It's making config object avaliable but not url.
它使配置对象可用,但URL不可用。
// __mocks__/config.js
jest.mock('config', ()=>({url: 'https://localhost'}), {virtual: true})
How can I add url propery to mocked module? 如何将网址属性添加到模拟模块?
Thank you. 谢谢。
Note: I need url since I will need it when using nock. 注意:我需要url,因为使用nock时将需要它。
Here it is; 这里是;
Looks like something elese was preventing me. 好像是elese阻止了我。
jest.mock("Config", ()=> ({url: 'https://localhost'}), {virtual: true});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.