Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ const TEXT_NODE = 3

// Currently this fn only supports jest timers, but it could support other test runners in the future.
function runWithRealTimers(callback) {
// istanbul ignore else
if (typeof jest !== 'undefined') {
return runWithJestRealTimers(callback).callbackReturnValue
}
return hasJestTimers()
? runWithJestRealTimers(callback).callbackReturnValue
: // istanbul ignore next
callback()
}

// istanbul ignore next
return callback()
function hasJestTimers() {
return (
typeof jest !== 'undefined' &&
jest !== null &&
typeof jest.useRealTimers === 'function'
)
}

function runWithJestRealTimers(callback) {
Expand Down Expand Up @@ -50,13 +55,10 @@ function runWithJestRealTimers(callback) {
}

function jestFakeTimersAreEnabled() {
// istanbul ignore else
if (typeof jest !== 'undefined') {
return runWithJestRealTimers(() => {}).usedFakeTimers
}

// istanbul ignore next
return false
return hasJestTimers()
? runWithJestRealTimers(() => {}).usedFakeTimers
: // istanbul ignore next
false
}

// we only run our tests in node, and setImmediate is supported in node.
Expand Down