如何在实习生测试中模拟依赖项 [英] How to mock dependencies in Intern tests

查看:17
本文介绍了如何在实习生测试中模拟依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实习生是否使用 requireJs 加载测试?我正在使用 这种方法 模拟出我要测试的模块的依赖关系,所以我想知道这是否也适用于 Intern.

Is intern use requireJs to load the test? I'm using this approach to mock out dependencies for the module I wanna test, so I wonder if this will work with Intern as well.

推荐答案

Intern 使用 Dojo Toolkit 的 AMD 加载器.要模拟依赖项,您应该能够只使用标准的 AMD map 功能.在您的实习生配置文件中,这样的内容应该可以满足您的需要:

Intern uses the Dojo Toolkit’s AMD loader. To mock out dependencies, you should be able to just use the standard AMD map feature. In your Intern configuration file, something like this should do what you need:

define({
  …,
  loader: {
    map: {
      myPackage: {
        'myPackage/foo': 'myPackage/mocks/foo',
        'herp': 'myPackage/mocks/herp',
        'derp': 'myPackage/mocks/derp'
      }
    }
  }
});

参见 https://github.com/amdjs/amdjs-api/wiki/Common-Config#map- 了解更多关于 map 的信息.

See https://github.com/amdjs/amdjs-api/wiki/Common-Config#map- for more information on map.

这篇关于如何在实习生测试中模拟依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆