Sha256: fb90273cd5da83b1a43aa0357da6966b709665bed7c12c1bfa134acb58741f1f

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

describe "WatCatcher", ->
  beforeEach ->
    @errorTarget = {}
    @errorTarget.onerror = -> "Howdy"
    @watCatcher = new WatCatcher @errorTarget
    @watCatcher.appEnvsToWorryAbout = ['production', 'staging', 'demo']
    @watCatcher.appEnv = 'production'

    @xmlhttp = jasmine.createSpyObj('XMLHttpRequest', ['send', 'setRequestHeader', 'open'])
    spyOn(window, 'XMLHttpRequest').andReturn(@xmlhttp)

    @msg = 'sadly, there was a terrible mistake'
    @line = '42'

  it "attaches watHandler to onerror argument", ->
    @watCatcher.watHandler(@msg, document.URL, @line)
    expect(@errorTarget.onerror).toEqual @watCatcher.watHandler

  it "preserves previous onerror handler", ->
    @watCatcher.watHandler(@msg, document.URL, @line)
    expect(@watCatcher.watHandler()).toEqual "Howdy"

  it "sends xhr on error", ->
    try
      window.goobilygoo()
    catch error
      @watCatcher.watHandler(error.message, document.URL, error.lineNumber)

    expect(@xmlhttp.send).toHaveBeenCalled()

  it "doesn't send wats in irrelevant appEnv", ->
    @watCatcher.appEnv = 'development'
    @watCatcher.watHandler(@msg, document.URL, @line)
    expect(@xmlhttp.send).not.toHaveBeenCalled()

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
wat_catcher-0.2.1 spec/javascripts/wat_catcher_spec.coffee
wat_catcher-0.2.0 spec/javascripts/wat_catcher_spec.coffee
wat_catcher-0.1.0 spec/javascripts/wat_catcher_spec.coffee
wat_catcher-0.0.8 spec/javascripts/wat_catcher_spec.coffee
wat_catcher-0.0.7 spec/javascripts/wat_catcher_spec.coffee
wat_catcher-0.0.6 spec/javascripts/wat_catcher_spec.coffee