 describe "RequireJS namespacing", ->
   beforeEach ->
+
+    #
+    #         * Jasmine does not provide a way to use the typeof operator. We need
+    #         * to create our own custom matchers so that a TypeError is not thrown.
+    #
     @addMatchers
       requirejsTobeUndefined: ->
         typeof requirejs is "undefined"

describe "RequireJS module creation", ->
  inDefineCallback = undefined
  inRequireCallback = undefined
  it "check that we can use RequireJS define() and require() a module", ->
    runs ->
      inDefineCallback = false
      inRequireCallback = false
      RequireJS.define "test_module", [], ->
        inDefineCallback = true
        module_status: "OK"

      RequireJS.require ["test_module"], (test_module) ->
        inRequireCallback = true
        expect(test_module.module_status).toBe "OK"


    waitsFor (->
      return false  if (inDefineCallback isnt true) or (inRequireCallback isnt true)
      true
    ), "We should eventually end up in the defined callback", 1000
    runs ->
      expect(inDefineCallback).toBeTruthy()
      expect(inRequireCallback).toBeTruthy()

    expect(window.RequireJS).toEqual jasmine.any(Object)

  it "check that requirejs(), require(), and define() are not in the global namespace", ->

    # The custom matchers that we defined in the beforeEach() function do
    # not operate on an object. We pass a dummy empty object {} not to
    # confuse Jasmine.
    expect({}).requirejsTobeUndefined()
    expect({}).requireTobeUndefined()
    expect({}).defineTobeUndefined()
