defaults to force: true for type and click

This commit is contained in:
Philipp Kühn
2020-09-15 09:03:08 +02:00
parent 71cc626b0a
commit 00506e359b
14 changed files with 94 additions and 63 deletions

View File

@@ -24,6 +24,23 @@
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
function defaults(object, name, value) {
if (!object) {
return {
[name]: value,
}
}
if (object[name] === undefined) {
return {
...object,
[name]: value,
}
}
return object
}
Cypress.Commands.overwrite('trigger', (originalFn, element, text, options) => {
if (text === 'keydown') {
const isMac = Cypress.platform === 'darwin'
@@ -31,7 +48,7 @@ Cypress.Commands.overwrite('trigger', (originalFn, element, text, options) => {
if (modKey) {
const newOptions = {
...rest,
...defaults(rest, 'force', true),
...(isMac ? { metaKey: modKey } : { ctrlKey: modKey }),
}
@@ -40,4 +57,16 @@ Cypress.Commands.overwrite('trigger', (originalFn, element, text, options) => {
}
return originalFn(element, text, options)
})
Cypress.Commands.overwrite('type', (originalFn, element, text, options) => {
const newOptions = defaults(options, 'force', true)
return originalFn(element, text, newOptions)
})
Cypress.Commands.overwrite('click', (originalFn, element, text, options) => {
const newOptions = defaults(options, 'force', true)
return originalFn(element, text, newOptions)
})