mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-14 04:29:04 +03:00
23 lines
721 B
CoffeeScript
23 lines
721 B
CoffeeScript
_ = require 'underscore'
|
|
|
|
describe "underscore extensions", ->
|
|
describe "_.adviseBefore", ->
|
|
[object, calls] = []
|
|
|
|
beforeEach ->
|
|
calls = []
|
|
object = {
|
|
method: (args...) ->
|
|
calls.push(["original", this, args])
|
|
}
|
|
|
|
it "calls the given function before the advised method", ->
|
|
_.adviseBefore object, 'method', (args...) -> calls.push(["advice", this, args])
|
|
object.method(1, 2, 3)
|
|
expect(calls).toEqual [['advice', object, [1, 2, 3]], ['original', object, [1, 2, 3]]]
|
|
|
|
it "cancels the original method's invocation if the advice returns true", ->
|
|
_.adviseBefore object, 'method', -> false
|
|
object.method(1, 2, 3)
|
|
expect(calls).toEqual []
|