{"action":"opened","issue":{"url":"https://api.github.com/repos/testdouble/testdouble.js/issues/51","labels_url":"https://api.github.com/repos/testdouble/testdouble.js/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/testdouble/testdouble.js/issues/51/comments","events_url":"https://api.github.com/repos/testdouble/testdouble.js/issues/51/events","html_url":"https://github.com/testdouble/testdouble.js/issues/51","id":117589375,"number":51,"title":"Using td.replace() with external modules","user":{"login":"jzaefferer","id":52585,"avatar_url":"https://avatars.githubusercontent.com/u/52585?v=3","gravatar_id":"","url":"https://api.github.com/users/jzaefferer","html_url":"https://github.com/jzaefferer","followers_url":"https://api.github.com/users/jzaefferer/followers","following_url":"https://api.github.com/users/jzaefferer/following{/other_user}","gists_url":"https://api.github.com/users/jzaefferer/gists{/gist_id}","starred_url":"https://api.github.com/users/jzaefferer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jzaefferer/subscriptions","organizations_url":"https://api.github.com/users/jzaefferer/orgs","repos_url":"https://api.github.com/users/jzaefferer/repos","events_url":"https://api.github.com/users/jzaefferer/events{/privacy}","received_events_url":"https://api.github.com/users/jzaefferer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-18T13:42:57Z","updated_at":"2015-11-18T13:42:57Z","closed_at":null,"body":"Based on the [node example](https://github.com/testdouble/testdouble.js/blob/master/examples/node/test/lib/car-test.js) I've tried to use `td.replace()` with a external module. The module I'm testing does something like this:\r\n```js\r\nimport elasticsearch from 'elasticsearch'\r\nvar client = new elasticsearch.Client({ ... })\r\nclient.search({ ... });\r\n```\r\nMy test, currently using sinon, does something like this:\r\n```js\r\nimport sinon from 'sinon'\r\nimport elasticsearch from 'elasticsearch'\r\nsearchSpy = {\r\n  search: sinon.stub().returns(Promise.resolve({\r\n    hits: {\r\n      hits: [ ... ]\r\n    }\r\n  }))\r\n}\r\nsinon.stub(elasticsearch, 'Client').returns(searchSpy)\r\n```\r\nStubbing only `elasticsearch.Client` is something I want to get rid of (to solve an unrelated problem). `td.replace()` seems like the right tool for that. So I tried something like this:\r\n```js\r\nimport elasticsearch from 'elasticsearch'\r\nimport td from 'testdouble'\r\nsearchSpy = {\r\n  search: sinon.stub().returns(Promise.resolve({\r\n    hits: {\r\n      hits: [ ... ]\r\n    }\r\n  }))\r\n}\r\nvar es = td.replace('elasticsearch')\r\ntd.when(es.Client()).return(searchSpy)\r\n```\r\nThat fails with `TypeError: es.Client is not a function`. `td.when(es.Client)` doesn't work either.\r\n\r\nSince there is no documentation for `td.replace()` and the example only imports internal module (with relative paths), I can't tell if I'm doing it wrong (likely) or if this is just not supported (yet, also likely).\r\n\r\nIf the snippets above aren't enough, I can also put together a sample that actually works."}}