Skip to content

Commit

Permalink
fix(type): correct wrapping (#388)
Browse files Browse the repository at this point in the history
Closes #387
  • Loading branch information
kentcdodds committed Jun 25, 2020
1 parent 8889776 commit 8161fa2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/type.js
Expand Up @@ -8,29 +8,30 @@ import {
getActiveElement,
calculateNewValue,
setSelectionRangeIfNecessary,
wrapInEventWrapper,
} from './utils'
import {click} from './click'

function wait(time) {
return new Promise(resolve => setTimeout(() => resolve(), time))
}

// this needs to be wrapped in the asyncWrapper for React's act and angular's change detection
// but only if it's actually going to be async.
// this needs to be wrapped in the event/asyncWrapper for React's act and angular's change detection
// depending on whether it will be async.
async function type(element, text, {delay = 0, ...options} = {}) {
// we do not want to wrap in the asyncWrapper if we're not
// going to actually be doing anything async, so we only wrap
// if the delay is greater than 0
let result
if (delay > 0) {
let result
await getDOMTestingLibraryConfig().asyncWrapper(async () => {
result = await typeImpl(element, text, {delay, ...options})
})
return result
} else {
return typeImpl(element, text, {delay, ...options})
getDOMTestingLibraryConfig().eventWrapper(() => {
result = typeImpl(element, text, {delay, ...options})
})
}
return result
}

async function typeImpl(
Expand Down Expand Up @@ -530,7 +531,6 @@ function getEventCallbackMap({
}
}
}
type = wrapInEventWrapper(type)

export {type}

Expand Down

0 comments on commit 8161fa2

Please sign in to comment.