UNPKG

581 BJavaScriptView Raw
1import _ from './wrap/lodash'
2import tdFunction from './function'
3import imitate from './imitate'
4
5export default (typeOrNames) =>
6 _.isFunction(typeOrNames)
7 ? imitate(typeOrNames)
8 : fakeConstructorFromNames(typeOrNames)
9
10const fakeConstructorFromNames = (funcNames) => {
11 return _.tap(tdFunction('(unnamed constructor)'), (fakeConstructor) => {
12 fakeConstructor.prototype.toString = () =>
13 '[test double instance of constructor]'
14
15 _.each(funcNames, (funcName) => {
16 fakeConstructor.prototype[funcName] = tdFunction(`#${String(funcName)}`)
17 })
18 })
19}