Sha256: 46f48f07e26f8a07bded520db47fdaa4ee8f8c9f534b1bec2e282fe20e8916de

Contents?: true

Size: 1.73 KB

Versions: 4

Compression:

Stored size: 1.73 KB

Contents

describe "Joosy.Modules.Events", ->

  beforeEach ->
    class @TestEvents extends Joosy.Module
      @include Joosy.Modules.Events
    class @SubTestEvents extends @TestEvents
      @include Joosy.Modules.Events
    @box = new @TestEvents()
    @sub = new @SubTestEvents()

  it "should run callback once when the all listed events have occurred", ->
    callback = sinon.spy()

    @box.wait 'events   list', callback

    @box.trigger 'events'
    expect(callback.callCount).toEqual 0
    @box.trigger 'list'
    expect(callback.callCount).toEqual 1

    @box.trigger 'events'
    expect(callback.callCount).toEqual 1
    @box.trigger 'list'
    expect(callback.callCount).toEqual 1

  it "should allow for binding and unbinding to events", ->
    callback = sinon.spy()

    @box.bind 'event', callback

    @box.trigger 'other-event'
    expect(callback.callCount).toEqual 0
    @box.trigger 'event'
    expect(callback.callCount).toEqual 1
    @box.trigger 'event'
    expect(callback.callCount).toEqual 2

    @box.unbind 'other-event'

    @box.trigger 'event'
    expect(callback.callCount).toEqual 3

    @box.unbind callback

    @box.trigger 'event'
    expect(callback.callCount).toEqual 3

  it "should handle inheritance well", ->
    callback = sinon.spy()
    @sub.wait 'foo', callback

    expect(@sub.__oneShotEvents).toEqual [[['foo'], callback]]
    expect(@box.__oneShotEvents).toBeUndefined()

  it "should be safe for concurrent usage", ->
    Joosy.synchronize (context) ->
      context.do (done)  ->
        window.setTimeout ->
          expect(-> done()).not.toThrow()
        , 1
    Joosy.synchronize (context) ->
      context.do (done)  ->
        window.setTimeout ->
          expect(-> done()).not.toThrow()
        , 2
    waits 3

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
joosy-1.0.0.RC4 spec/javascripts/joosy/core/modules/events_spec.js.coffee
joosy-1.0.0.RC3 spec/javascripts/joosy/core/modules/events_spec.js.coffee
joosy-1.0.0.RC2 spec/javascripts/joosy/core/modules/events_spec.js.coffee
joosy-1.0.0.RC1 spec/javascripts/joosy/core/modules/events_spec.js.coffee