2

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.

Community
  • 1
  • 1
Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297

2 Answers2

8

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.

C Snover
  • 17,908
  • 5
  • 29
  • 39
  • How would I mock per test then? Im not familiar with Dojos AMD implementation, so would it be possible to create an own context for every test like described in the SO I've mentioned in my question? – Andreas Köberle May 01 '13 at 20:01
  • Currently, the Dojo loader doesn’t support exactly the same things that RequireJS does with regards to creating `require`s with independent configs. This is a feature I would like to add to better support this use case. You can do something similar today by combining the `undef` function with `map`, but it’s not as graceful, so I wouldn’t recommend doing it directly. In the interim, you should be able to just replace loading `dojo/dojo.js` with `require.js` (in `client.html`, `client.js`, and `runner.js`) and everything should still work. Please put in a feature request. – C Snover May 01 '13 at 20:56
  • 1
    Intern 1.5 will include a `require.undef` API, so you can remove modules from the cache if you need to modify the configuration to mock an AMD dependency for a test. – C Snover Feb 25 '14 at 16:15
2

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.

Scott
  • 117
  • 7