How to mock dependencies in Intern tests [closed]

2019-01-28 20:54发布

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.

2条回答
贼婆χ
2楼-- · 2019-01-28 21:42

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'
      }
    }
  }
});

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

查看更多
Luminary・发光体
3楼-- · 2019-01-28 21:48

Not sure if this would be helpful. I've created a module for mocking module dependencies using the Dojo loader: https://github.com/stdavis/StubModule

Works well for my needs. I don't see any reason why it wouldn't work in intern but haven't tried it yet.

查看更多
登录 后发表回答