UNPKG

829 BJavaScriptView Raw
1import config from '../config'
2import log from '../log'
3
4const MESSAGES = {
5 warn: `\
6no promise constructor is set, so this \`thenResolve\` or \`thenReject\` stubbing
7will fail if it's satisfied by an invocation on the test double. You can tell
8testdouble.js which promise constructor to use with \`td.config\`, like so:`,
9 error: `\
10no promise constructor is set (perhaps this runtime lacks a native Promise
11function?), which means this stubbing can't return a promise to your
12subject under test, resulting in this error. To resolve the issue, set
13a promise constructor with \`td.config\`, like this:`
14}
15
16export 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}