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

cy.trigger('mousedown', ...) doesn't fill in event.view property #3686

Closed
fr0 opened this issue Mar 11, 2019 · 3 comments · Fixed by #8305
Closed

cy.trigger('mousedown', ...) doesn't fill in event.view property #3686

fr0 opened this issue Mar 11, 2019 · 3 comments · Fixed by #8305
Labels
pkg/driver This is due to an issue in the packages/driver directory type: bug

Comments

@fr0
Copy link

fr0 commented Mar 11, 2019

Current behavior:

  cy.get('#thing').trigger('mousedown', 10, 10);

When the browser creates the MouseEvent object, it has a view property which points to the Window object.

Cypress does not add it during a trigger.

Apparently the d3-zoom library depends on this property being there. My app breaks when run via cypress but not when the user clicks.

Here is the property:
https://github.com/Microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L15454

Desired behavior:

During a trigger, fill in all of the same properties that the browser does when the user clicks.

Steps to reproduce: (app code and test code)

https://stackblitz.com/edit/typescript-eurovj?file=index.ts

  it('should click just like the user does', () => {
    cy.visit('https://typescript-eurovj.stackblitz.io');
    cy.get('#rect').trigger('mousedown', 5, 5);
    cy.get('#app').should('contain', 'got the view');
  });

Versions

Cypress 3.1.5

@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Mar 19, 2019
@jennifer-shehane jennifer-shehane added type: bug pkg/driver This is due to an issue in the packages/driver directory labels Mar 19, 2019
@OSInsight
Copy link

OSInsight commented May 23, 2019

By the way, I find sth confused in cy.trigger()
https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/actions/trigger.coffee#L9

event = new Event(eventName, options) // why not new MouseEvent or ?

This occurs Cypress can not test React re-resizable.
https://github.com/bokuweb/re-resizable/blob/master/src/index.tsx#L659

const clientX = event instanceof MouseEvent ? event.clientX : event.touches[0].clientX;

cc @jennifer-shehane Thanks.


ok, give a pr to re-resizable #439


ok, I have figured it out.

Attention:

  1. Cypress MouseEvent !== Window.MouseEvent
  2. window.addEventListener('mousemove', this.onMouseMove); in re-resizable
cy.wrap(mousedownDom).trigger('mousedown', { which: 1 });

cy.window()
  .then(win => {
    win.dispatchEvent(
      new win.MouseEvent('mousemove', {
        bubbles: true, // must
        clientX: deltaWidth,
        clientY: deltaHeight,
      })
    );
  })
  .trigger('mouseup', { which: 1 });

@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope stage: work in progress stage: needs review The PR code is done & tested, needs review labels Aug 18, 2020
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: work in progress and removed stage: work in progress stage: needs review The PR code is done & tested, needs review labels Aug 25, 2020
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Aug 31, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Aug 31, 2020

The code for this is done in cypress-io/cypress#8305, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 1, 2020

Released in 5.1.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.1.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pkg/driver This is due to an issue in the packages/driver directory type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants