【问题标题】:How to not include mocha (TDD) functions like "describe" and "it" in my src folder and only contain them in test folder? [TS]如何在我的 src 文件夹中不包含 mocha (TDD) 函数,如“describe”和“it”,而只包含在 test 文件夹中? [TS]
【发布时间】:2021-11-15 10:09:39
【问题描述】:

像 describe() 和 it() 这样的 Mocha.js 函数在我的项目中随处可用,但我只希望它们在我的“测试”文件夹中可访问和可调用。有什么办法吗?

附:如果有什么不同,我会使用打字稿。

【问题讨论】:

    标签: javascript typescript mocha.js tdd


    【解决方案1】:

    我认为你的问题真的很模糊。我仍然会尝试回答你使用 eslint...

    在您的 .eslintrc.js(或 eslint 配置文件)中,您可能有:

    module.exports = {
      env: {
        browser: true,
        es6: true,
        node: true,
        mocha: true
       }
       (...)
    

    你应该有的地方:

    module.exports = {
      env: {
        browser: false,
        es6: true,
        node: true
      },
    
      (...)
    
      overrides: [
        {
          files: 'test/**/*.spec.js',
          env: {
            mocha: true,
          },
        },
      ],
    

    【讨论】:

    • 我编辑了我的问题,看看现在是否更好。对于你对 eslint 的建议,我不是很熟悉,具体是如何工作的?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-24
    • 1970-01-01
    • 2022-11-29
    • 2019-08-27
    • 2014-12-08
    • 2015-04-20
    • 2011-09-14
    相关资源
    最近更新 更多