【问题标题】:node-config Config is `undefined` in typescript jest context?node-config Config 在 typescript jest 上下文中是“未定义”吗?
【发布时间】:2020-05-02 12:47:04
【问题描述】:

我有一个可用于开发和生产的打字稿模块。它使用https://github.com/lorenwest/node-config 我正在尝试将它导入到 jest 中以编写测试,它会抛出一个错误,表明配置对象未定义

TypeError: Cannot read property 'get' of undefined
at Object.<anonymous> (src/email/email.service.ts:1877:43)

来自

import config from 'config'
console.log('**********CONFIG GET*********', config); // undefined
const sendgridToken: string = config.get('socialApi.value') // throws error

我希望 config 被定义为配置模块的默认导出

环境:

node-config version: config@3.2.4
node-version: 12.13.1
tsc -v
Version 3.7.4
ts-jest@24.3.0

【问题讨论】:

    标签: javascript node.js typescript jestjs


    【解决方案1】:

    而不是

    import config from 'config'
    

    写这个

    import * as config from 'config'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-23
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 2022-01-11
      • 2020-01-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多