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.19 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.18 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.17 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.16 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.15 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.14 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.13 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.12 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.11 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.10 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.9 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.8 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.7 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.6 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.5 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.alpha.4 spec/joosy/core/modules/module_spec.coffee
joosy-1.1.0 spec/javascripts/joosy/core/modules/module_spec.js.coffee
joosy-1.1.0.alpha.3 spec/javascripts/joosy/core/modules/module_spec.js.coffee
joosy-1.1.0.alpha.2 spec/javascripts/joosy/core/modules/module_spec.js.coffee
joosy-1.1.0.alpha.1 spec/javascripts/joosy/core/modules/module_spec.js.coffee