Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Ability to inject dependencies #52

Open
julianlconnor opened this issue Oct 3, 2013 · 0 comments
Open

Ability to inject dependencies #52

julianlconnor opened this issue Oct 3, 2013 · 0 comments

Comments

@julianlconnor
Copy link

Is it possible to inject module dependencies into stitched files for client side testing purposes?

E.g.,
// bar.js

var foo = require('../foo');

module.exports = function() {
  return foo();
};

// bar.test.js

var bar = require('bar');

// I want to mock foo.
describe('bar', function() {
   it('calls foo', function() {
      // how would you go about doing this?
   });
});

My solution was to add a method onto window that would allow you to do this following:
// bar.stub.test.js

var mock = sinon.mock();
var bar = requireAndInject('bar', { '../foo', mock);

// I want to mock foo.
describe('bar', function() {
   it('calls foo', function() {
      mock.once();
      bar();
      mock.verify();
   });
});

I can submit a pull request if deemed helpful. This seems to be the only solution for browser testing rendr apps.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant