spur-common
Version:
A Node.JS library of common modules used as a base to most Node.JS applications.
57 lines (47 loc) • 1.48 kB
text/coffeescript
describe "BaseDelegate", ->
beforeEach ->
= []
mockConsole =
log:(args...)=> .push(args)
injector()
.addDependency("console", mockConsole, true)
.inject ()=>
class extends
constructor:()->
[
"log", "debug"
]
it "base delegate test", ->
delegate = new
delegate.log("hi")
delegate.debug("hello")
expect().to.deep.equal [
[ '\u001b[36mSomeDelegate#log: \u001b[39m', 'hi' ],
[ '\u001b[36mSomeDelegate#debug: \u001b[39m', 'hello' ]
]
delegate.useRecorder()
delegate.log("hi2")
delegate.debug("hello2")
expect(delegate.recorded.log).to.deep.equal [["hi2"]]
expect(delegate.recorded.debug).to.deep.equal [["hello2"]]
delegate.use({
log:()=>
debug:()=>
})
delegate.log("foo")
delegate.debug("bar")
expect().to.equal "foo"
expect().to.equal "bar"
it "multiple delegates", ->
delegate = new
delegate.delegates = [
delegate.consoleDelegate
delegate.consoleDelegate
delegate.consoleDelegate
]
delegate.log("foo")
expect().to.deep.equal [
[ '\u001b[36mSomeDelegate#log: \u001b[39m', 'foo' ],
[ '\u001b[36mSomeDelegate#log: \u001b[39m', 'foo' ],
[ '\u001b[36mSomeDelegate#log: \u001b[39m', 'foo' ]
]