1 | import _ from './wrap/lodash'
|
2 | import tdFunction from './function'
|
3 | import imitate from './imitate'
|
4 |
|
5 | export default (typeOrNames) =>
|
6 | _.isFunction(typeOrNames)
|
7 | ? imitate(typeOrNames)
|
8 | : fakeConstructorFromNames(typeOrNames)
|
9 |
|
10 | const 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 | }
|