Sha256: 080ead050699b9e240c4140f60aa56e30590815f3d9c083b104e165c1bd99698

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

describe "Joosy.Module", ->

  it "tracks 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 a, b).toBeTruthy()
        else
          expect(Joosy.Module.hasAncestor a, b).toBeFalsy()

  # We need this check to ensure we are not overpolluting the namespace
  it "has minimal set of properties", ->
    class Klass extends Joosy.Module

    expect(Object.keys Klass).toEqual ['__namespace__', '__className', 'hasAncestor', 'aliasMethodChain', 'aliasStaticMethodChain', 'merge', 'include', 'extend', '__super__']
    expect(Object.keys Klass.prototype).toEqual ['constructor']

  it "includes", ->
    Module =
      property: 'value'

    class Klass extends Joosy.Module
      @include Module

    expect(Klass::property).toEqual 'value'
    expect(Klass.property).toBeUndefined()

  it "extends", ->
    TestModule =
      property: 'value'

    class Klass extends Joosy.Module
      @extend TestModule

    expect(Klass.property).toEqual 'value'
    expect(Klass::property).toBeUndefined()

  it "runs callbacks", ->
    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()

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
joosy-1.2.0.beta.4 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.beta.3 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.beta.2 spec/joosy/core/modules/module_spec.coffee
joosy-1.2.0.beta.1 spec/joosy/core/modules/module_spec.coffee