mojio-js-sdk
Version:
Mojio javascript REST client.
175 lines (140 loc) • 4.8 kB
text/coffeescript
should = require('should')
Module = require '../../template/helpers/Module'
#class Module
# constructor: () ->
#
# : (obj) ->
# for key, value of obj when key not in moduleKeywords
# @[key] = value
# obj.extended?.apply(@)
# @
#
# : (obj) ->
# for key, value of obj when key not in moduleKeywords
# @::[key] = value
# obj.included?.apply(@)
# @
describe 'Test Module', ->
it 'Module can extend from object', ->
classProperties =
tuning: () ->
return true
class Guitar extends Module
classProperties
Guitar.tuning().should.be.true
it 'Module can include from object', ->
instanceProperties =
makeSound: () ->
return true
class Guitar extends Module
instanceProperties
guitar = new Guitar()
guitar.makeSound().should.be.true
it 'Module can extend from class', ->
class classProperties
tuning: () ->
return true
class Guitar extends Module
classProperties
Guitar.tuning().should.be.true
it 'Module can include from class', ->
class instanceProperties
makeSound: () ->
return true
class Guitar extends Module
instanceProperties
guitar = new Guitar()
guitar.makeSound().should.be.true
# it 'Module can extend from object in constructor', ->
# classProperties1 =
# tuning: () ->
# return true
#
# class Guitar3 extends Module
# constructor: () ->
# classProperties1
#
# guitar = new Guitar3()
# Guitar3.tuning().should.be.true
#
# it 'Module can extend from class in constructor', ->
# class classProperties2
# tuning: () ->
# return true
#
# class Guitar2 extends Module
# constructor:() ->
# classProperties2
#
# guitar = new Guitar2()
# Guitar2.tuning().should.be.true
it 'Module can include from object in constructor', ->
instanceProperties =
makeSound: () ->
return true
class Guitar extends Module
constructor: () ->
instanceProperties
guitar = new Guitar()
guitar.makeSound().should.be.true
it 'Module can include from class in constructor', ->
class instanceProperties
makeSound: () ->
return true
class Guitar extends Module
constructor: () ->
instanceProperties
guitar = new Guitar()
guitar.makeSound().should.be.true
it "Module can't include from hidden variables", ->
try
class instanceProperties
state = {}
makeSound: () ->
stateMachine["thing"] = true
return true
class Guitar extends Module
constructor: () ->
instanceProperties
makeAnotherSound: () ->
try
stateMachine["thing"] = true
catch
return true
return true
guitar = new Guitar()
guitar.makeSound().should.be.true
guitar.makeAnotherSound().should.be.true
catch
true.should.be.true
it "Module can't include from hidden variables", ->
class State
stuff = {stuff: "hi"}
constructor: () ->
= {stuff: "hi"}
set: () ->
stuff['thing'] = true
reset: () ->
stuff['thing'] = false
show: () ->
return stuff
class instanceProperties
constructor: () ->
makeSound: () ->
console.log(JSON.stringify(.show()))
.set()
console.log(JSON.stringify(.show()))
return true
class Guitar extends Module
constructor: () ->
super()
instanceProperties
= new State()
makeAnotherSound: () ->
console.log(JSON.stringify(.show()))
.reset()
console.log(JSON.stringify(.show()))
return true
guitar = new Guitar()
guitar.makeSound().should.be.true
guitar.makeAnotherSound().should.be.true