i-like-robots / rewireify

Rewireify is a port of Rewire for Browserify that adds setter and getter methods to each module so that their behaviour can be modified for better unit testing.
https://www.npmjs.com/package/rewireify
Other
59 stars 10 forks source link

module.__set__(map) errors when using nested properties #6

Closed jstejada closed 9 years ago

jstejada commented 9 years ago

Hi!

I'm trying to set a nested property passing a map as a parameter to __set__:

# module.coffee

privateModule = require './privateModule'

module.exports = ()->
  privateModule.func()
# moduleTest.coffee

module = require './module'

module.__set__({"privateModule.func": jasmine.createSpy()})

But it errors with: TypeError: Cannot read property 'func' of undefined

Any thoughts on this? Thanks!

i-like-robots commented 9 years ago

Your code looks fine to me, will investigate.

i-like-robots commented 9 years ago

Have you tried setting the property individually?

module.__set__("privateModule.func", jasmine.createSpy())

I have added a test for this in 18f3bae1d9df17acfd8bd77dd958da30fc94653e

jstejada commented 9 years ago

Thanks for checking, setting the property individually does work, so I resorted to that.

i-like-robots commented 9 years ago

Unfortunately it is not possible to set multiple, nested vars without seriously complicating the __set__ method so that usage has been removed from the readme, see 91e7c9982f6af9be67ca7bdb671629ec553b1ea6

jstejada commented 9 years ago

ok no problem. thanks!