Skip to content

Commit

Permalink
eventType -> constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Aug 28, 2020
1 parent 8d1b5b5 commit e1455d8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2914,7 +2914,7 @@ declare namespace Cypress {
*
* @default 'Event'
*/
eventType: string
constructor: string
}

/** Options to change the default behavior of .writeFile */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe('src/cy/commands/actions/trigger', () => {
})

cy.get('input:first').trigger('mousedown', {
eventType: 'MouseEvent',
constructor: 'MouseEvent',
button: 0,
shiftKey: false,
ctrlKey: false,
Expand Down Expand Up @@ -778,7 +778,7 @@ describe('src/cy/commands/actions/trigger', () => {
})

cy.get('input:first').trigger('keydown', {
eventType: 'KeyboardEvent',
constructor: 'KeyboardEvent',
keyCode: 65,
which: 65,
shiftKey: false,
Expand All @@ -790,7 +790,7 @@ describe('src/cy/commands/actions/trigger', () => {
cy.visit('fixtures/issue-5650.html')

cy.get('#test-input').trigger('keydown', {
eventType: 'KeyboardEvent',
constructor: 'KeyboardEvent',
keyCode: 65,
which: 65,
shiftKey: false,
Expand All @@ -813,7 +813,7 @@ describe('src/cy/commands/actions/trigger', () => {
})

cy.get('input:first').trigger('mousedown', {
eventType: 'MouseEvent',
constructor: 'MouseEvent',
button: 0,
shiftKey: false,
ctrlKey: false,
Expand All @@ -823,7 +823,7 @@ describe('src/cy/commands/actions/trigger', () => {
it('should trigger MouseEvent with .trigger inside html script event listener', () => {
cy.visit('fixtures/issue-5650.html')
cy.get('#test-input').trigger('mousedown', {
eventType: 'MouseEvent',
constructor: 'MouseEvent',
button: 0,
shiftKey: false,
ctrlKey: false,
Expand Down Expand Up @@ -958,13 +958,13 @@ describe('src/cy/commands/actions/trigger', () => {
it('throws when provided invalid event type', function (done) {
cy.on('fail', (err) => {
expect(this.logs.length).to.eq(2)
expect(err.message).to.eq('Timed out retrying: `cy.trigger()` `eventType` option must be a valid event (e.g. \'MouseEvent\', \'KeyboardEvent\'). You passed: `FooEvent`')
expect(err.message).to.eq('Timed out retrying: `cy.trigger()` `constructor` option must be a valid event (e.g. \'MouseEvent\', \'KeyboardEvent\'). You passed: `FooEvent`')

done()
})

cy.get('button:first').trigger('mouseover', {
eventType: 'FooEvent',
constructor: 'FooEvent',
})
})

Expand Down
10 changes: 5 additions & 5 deletions packages/driver/src/cy/commands/actions/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ const $errUtils = require('../../../cypress/error_utils')
const $actionability = require('../../actionability')

const dispatch = (target, appWindow, eventName, options) => {
const eventType = options.eventType ?? 'Event'
const ctor = appWindow[eventType]
const constructor = options.constructor ?? 'Event'
const ctor = appWindow[constructor]

if (typeof ctor !== 'function') {
$errUtils.throwErrByPath('trigger.invalid_event_type', {
args: { eventType },
args: { constructor },
})
}

// eventType property should not be added to event instance.
delete options.eventType
// constructor property should not be added to event instance.
delete options.constructor

// https://github.com/cypress-io/cypress/issues/3686
// UIEvent and its derived events like MouseEvent, KeyboardEvent
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cypress/error_messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ module.exports = {
docsUrl: 'https://on.cypress.io/trigger',
},
invalid_event_type: {
message: `${cmd('trigger')} \`eventType\` option must be a valid event (e.g. 'MouseEvent', 'KeyboardEvent'). You passed: \`{{eventType}}\``,
message: `${cmd('trigger')} \`constructor\` option must be a valid event (e.g. 'MouseEvent', 'KeyboardEvent'). You passed: \`{{constructor}}\``,
docsUrl: 'https://on.cypress.io/trigger',
},
},
Expand Down

0 comments on commit e1455d8

Please sign in to comment.