Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(type): correct wrapping #388

Merged
merged 1 commit into from Jun 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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