1 | import config from '../config'
|
2 | import log from '../log'
|
3 |
|
4 | const MESSAGES = {
|
5 | warn: `\
|
6 | no promise constructor is set, so this \`thenResolve\` or \`thenReject\` stubbing
|
7 | will fail if it's satisfied by an invocation on the test double. You can tell
|
8 | testdouble.js which promise constructor to use with \`td.config\`, like so:`,
|
9 | error: `\
|
10 | no promise constructor is set (perhaps this runtime lacks a native Promise
|
11 | function?), which means this stubbing can't return a promise to your
|
12 | subject under test, resulting in this error. To resolve the issue, set
|
13 | a promise constructor with \`td.config\`, like this:`
|
14 | }
|
15 |
|
16 | export default function ensurePromise (level) {
|
17 | if (config().promiseConstructor == null) {
|
18 | log[level]('td.when', `\
|
19 | ${MESSAGES[level]}
|
20 |
|
21 | td.config({
|
22 | promiseConstructor: require('bluebird')
|
23 | })\
|
24 | `
|
25 | )
|
26 | }
|
27 | }
|