Sha256: d31094ed94760a5723d8e83bf2a3a319becb3baf3a17bb16aa849271bb7edb4f

Contents?: true

Size: 1.58 KB

Versions: 46

Compression:

Stored size: 1.58 KB

Contents

describe "Joosy.Module", ->

  it "should track inheritance", ->
    class A
    class B extends A
    class C extends B
    class D
    for a in [A, B, C, D]
      for b in [A, B, C, D]
        if (a == b) ||
          ((a == B) && (b == A)) ||
          ((a == C) && (b != D))
            expect(Joosy.Module.hasAncestor.apply(null, [a, b])).toBeTruthy()
        else
          expect(Joosy.Module.hasAncestor.apply(null, [a, b])).toBeFalsy()

  it "should include properties into prototype", ->
    TestModule =
      property: 'value'
    class Klass extends Joosy.Module
      @include TestModule
    expect(Klass::property).toEqual 'value'
    expect((new Klass()).property).toEqual 'value'

  it "should extend object", ->
    TestModule =
      property: 'value'
    class Klass extends Joosy.Module
      @extend TestModule
    expect(Klass.property).toEqual 'value'
    expect((new Klass()).property).toBeUndefined()

  it "should run callbacks on include and extend", ->
    TestModule =
      property: 'value'
      included: sinon.spy()
      extended: sinon.spy()
    class Klass extends Joosy.Module
      @include TestModule
      @extend TestModule
    for callback in ['included', 'extended']
      expect(TestModule[callback].callCount).toEqual 1
      expect(TestModule[callback].getCall(0).calledOn(Klass)).toBeTruthy()

  it "should have minimal set of properties", ->
    expect(Object.extended(Joosy.Module).keys()).toEqual ['__namespace__', '__className', 'hasAncestor', 'alias', 'aliasStatic', 'merge', 'include', 'extend']
    expect(Object.extended(Joosy.Module.prototype).keys()).toEqual []

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
joosy-1.2.0.alpha.38 spec/joosy/core/modules/module_spec.coffee
joosy-1.1.2 spec/javascripts/joosy/core/modules/module_spec.js.coffee
joosy-1.2.0.alpha.37 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.36 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.35 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.34 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.33 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.32 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.31 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.30 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.29 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.28 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.27 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.25 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.24 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.23 spec/joosy/core/modules/module_spec.coffee
joosy-1.1.1 spec/javascripts/joosy/core/modules/module_spec.js.coffee
joosy-1.2.0.alpha.22 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.21 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.20 spec/joosy/core/modules/module_spec.coffee