Re: spying on requireJS's require within an AMD module

40 views
Skip to first unread message

Gavin Jackson

unread,
Nov 9, 2012, 4:16:57 AM11/9/12
to jasmi...@googlegroups.com
I figured this out, FYI it turns out all that was needed to be done was to spy on window.  This is more a CoffeeScript thing than anything else, as thats the only way CoffeeScript can access globals (what with not having `var`)

spyOn(window, 'require').andCallFake (dependencies, callBack, errorCallBack) ->

  errorCallBack.call()


Hope someone finds that useful

On Thursday, 8 November 2012 10:48:06 UTC, Gavin Jackson wrote:
Hi

I am using RequireJS to load AMD modules on demand inside of an AMD module already loaded using RequireJS.  I want to mock the `require()` call which is part of my testable code. 

My class under test looks like:

define ['some/dependencies/here'], (dependency) ->
  class ClassUnderTest
    ..
    ..
    _addWidget: (payload) ->
        require [payload.dependency], (dependency) ->
          #stuff i want to test in here

Cheers 

Gavin
Reply all
Reply to author
Forward
0 new messages