Skip to content

feat: added typehint to the trigger method #551

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

Merged
merged 9 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@vue/compiler-sfc": "3.0.11",
"babel-jest": "^26.6.3",
"babel-preset-jest": "^26.6.2",
"dom-event-types": "^1.0.0",
"husky": "^6.0.0",
"jest": "25.5.4",
"jsdom": "^16.5.3",
Expand Down
50 changes: 28 additions & 22 deletions src/baseWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { textContent } from './utils'
import { createDOMEvent } from './createDomEvent'
import type { TriggerOptions } from './createDomEvent'
import { nextTick } from 'vue'
import { createDOMEvent } from './createDomEvent'
import { DomEventName } from './constants/dom-event-types'

export default class BaseWrapper<ElementType extends Element> {
private readonly wrapperElement: ElementType
Expand Down Expand Up @@ -44,6 +45,31 @@ export default class BaseWrapper<ElementType extends Element> {
return true
}

protected isDisabled = () => {
const validTagsToBeDisabled = [
'BUTTON',
'COMMAND',
'FIELDSET',
'KEYGEN',
'OPTGROUP',
'OPTION',
'SELECT',
'TEXTAREA',
'INPUT'
]
const hasDisabledAttribute = this.attributes().disabled !== undefined
const elementCanBeDisabled = validTagsToBeDisabled.includes(
this.element.tagName
)

return hasDisabledAttribute && elementCanBeDisabled
}

async trigger(
eventString: DomEventName,
options?: TriggerOptions
): Promise<void>
async trigger(eventString: string, options?: TriggerOptions): Promise<void>
async trigger(eventString: string, options?: TriggerOptions) {
if (options && options['target']) {
throw Error(
Expand All @@ -53,27 +79,7 @@ export default class BaseWrapper<ElementType extends Element> {
)
}

const isDisabled = () => {
const validTagsToBeDisabled = [
'BUTTON',
'COMMAND',
'FIELDSET',
'KEYGEN',
'OPTGROUP',
'OPTION',
'SELECT',
'TEXTAREA',
'INPUT'
]
const hasDisabledAttribute = this.attributes().disabled !== undefined
const elementCanBeDisabled = validTagsToBeDisabled.includes(
this.element.tagName
)

return hasDisabledAttribute && elementCanBeDisabled
}

if (this.element && !isDisabled()) {
if (this.element && !this.isDisabled()) {
const event = createDOMEvent(eventString, options)
this.element.dispatchEvent(event)
}
Expand Down
Loading