let Test = require('packhouse/plugins/Test')
let Packhouse = require('Packhouse')
let packhouse = new Packhouse()
packhouse.plugin(Test)
let group = {
tools: {
sum: {
handler(self, v1, v2) {
self.success(v1 + v2)
}
}
}
}
packhouse.addGroup('math', () => ({ data: group }))
// mock options
packhouse.test.mock('tool', 'math/sum', options => {
options.handler = self => self.success(50)
})
packhouse.tool('math/sum').action(10, 20, (error, result) => {
console.log(result) // 50
})
// restore
packhouse.test.restore('tool', 'math/sum')
packhouse.tool('math/sum').action(10, 20, (error, result) => {
console.log(result) // 30
})
packhouse.test.restoreAll()
let { expect } = require('chai')
let Test = require('packhouse/plugins/Test')
let Packhouse = require('Packhouse')
let packhouse = new Packhouse()
packhouse.plugin(Test)
let group = {
tools: {
sum: {
handler(self, v1, v2) {
self.success(v1 + v2)
}
}
}
}
describe('#Test', function() {
this.timeout(0)
before(function() {
packhouse.test.mock('tool', 'math/sum', options => {
options.handler = self => self.success(50)
})
})
after(function() {
packhouse.test.restore('tool', 'math/sum')
})
it('test', function(done) {
packhouse.tool('math/sum').action(10, 10, (error, result) => {
expect(result).to.equal(50)
})
})
})