chai-spies-decorators
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -25,31 +25,41 @@ import chai from 'chai' | ||
const spied = chai.spy (desc.value) | ||
const check = () => { | ||
const memo = Symbol () | ||
let prev = undefined, | ||
next = chai.expect (spied).to | ||
return { | ||
chain.forEach (what => { | ||
configurable: desc.configurable, | ||
enumerable: desc.enumerable, | ||
if (Array.isArray (what)) { // call args | ||
get () { | ||
next = next.apply (prev, what) // prev.next (what) | ||
/* memoization */ | ||
} else { // .what | ||
if (this[memo]) { | ||
return this[memo] } | ||
else { | ||
prev = next | ||
next = next[what] | ||
} | ||
}) | ||
} | ||
const spied = chai.spy (desc.value) | ||
checklist.push (check) | ||
checklist.push (() => { | ||
return { | ||
let prev = undefined, | ||
next = chai.expect (spied).to | ||
configurable: desc.configurable, | ||
enumerable: desc.enumerable, | ||
chain.forEach (what => { | ||
get () { | ||
return (...args) => spied.apply (this, args) | ||
if (Array.isArray (what)) { // call args | ||
next = next.apply (prev, what) // prev.next (what) | ||
} else { // .what | ||
prev = next | ||
next = next[what] | ||
} | ||
}) | ||
}) | ||
return (this[memo] = spied) | ||
} | ||
} | ||
@@ -56,0 +66,0 @@ } |
{ | ||
"name": "chai-spies-decorators", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Chai Spies + ES7 decorators", | ||
@@ -5,0 +5,0 @@ "main": "chai-spies-decorators.js", |
18
test.js
@@ -12,9 +12,15 @@ import './chai-spies-decorators' | ||
const foo = new (class Foo { | ||
class Foo { | ||
@will.have.been.called.with ('qux').once | ||
bar (qux) { return qux + qux } | ||
}) | ||
bar (qux) { | ||
return qux + qux | ||
} | ||
} | ||
foo.bar ('qux').should.equal ('quxqux') | ||
const foo1 = new Foo () | ||
const foo2 = new Foo () | ||
foo1.bar ('qux').should.equal ('quxqux') | ||
foo2.bar ('qux').should.equal ('quxqux') | ||
}) | ||
@@ -55,6 +61,6 @@ | ||
@will.have.been.called.once | ||
bar () { } | ||
bar () { this.should.equal (foo) } | ||
@will.have.been.called.twice | ||
baz () { } | ||
baz () { this.should.equal (foo) } | ||
}) | ||
@@ -61,0 +67,0 @@ |
8730
127