Skip to content

Commit

Permalink
patch: use isPromise utility (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 15, 2020
1 parent 670887d commit 56b195d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"isFunction": [
"./packages/__shared/src/isFunction.js"
],
"isPromise": [
"./packages/__shared/src/isPromise.js"
],
"isStringValue": [
"./packages/__shared/src/isStringValue.js"
],
Expand Down
5 changes: 5 additions & 0 deletions packages/__shared/src/isPromise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import isFunction from 'isFunction';

export default function isPromise(value) {
return value && isFunction(value.then);
}
3 changes: 2 additions & 1 deletion packages/vest/src/core/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import addTestToState from 'addTestToState';
import context from 'ctx';
import { isExcluded } from 'exclusive';
import isFunction from 'isFunction';
import isPromise from 'isPromise';
import { setPending } from 'pending';
import runAsyncTest from 'runAsyncTest';
import bindTestMemo from 'test.memo';
Expand Down Expand Up @@ -43,7 +44,7 @@ const register = testObject => {
try {
// try catch for safe property access
// in case object is an enforce chain
if (isFunction(result?.then)) {
if (isPromise(result)) {
testObject.asyncTest = result;
setPending(testObject);
runAsyncTest(testObject);
Expand Down
4 changes: 2 additions & 2 deletions packages/vest/src/core/test/test.memo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import addTestToState from 'addTestToState';
import createCache from 'cache';
import { isExcluded } from 'exclusive';
import isFunction from 'isFunction';
import { isNull } from 'isNull';
import isPromise from 'isPromise';
import { setPending } from 'pending';
import runAsyncTest from 'runAsyncTest';
import useSuiteId from 'useSuiteId';
Expand Down Expand Up @@ -42,7 +42,7 @@ export default function bindTestMemo(test) {

addTestToState(testObject);

if (isFunction(testObject?.asyncTest?.then)) {
if (isPromise(testObject?.asyncTest)) {
setPending(testObject);
runAsyncTest(testObject);
}
Expand Down

0 comments on commit 56b195d

Please sign in to comment.