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: mock brower event about issues 1327 #1328

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

electroluxcode
Copy link

@electroluxcode electroluxcode commented Jul 15, 2024

fix #1327

this pr is about mock brower event, it is a possible solutions to the #1327) issues

What:
This PR adds two new lifecycle methods, before and cond, developers only need to control these two lifecycles to simulate most browser behaviors.. on top of the existing ones to simulate browser events. This is just a draft; please do not merge.

Why:

The events in dom-testing-library are encapsulated based on the native Event class. However, when there are conflicts between this Event and native DOM events, it may not fully replicate the behavior.

How:

Checklist:

  • Documentation added to the
    docs site
  • Tests
  • TypeScript definitions updated
  • Ready to be merged

before this pr, it will trigger dragstar and dragover event ,it is error because dragstart is prevent,it should only trigger dragstart event
after this pr ,when i test this case ,it 'll be as expect


test('assigns dataTransfer properties', () => {
  const node = document.createElement('div')
  node.addEventListener('dragstart', (e)=>{
    e.preventDefault()
  })
  node.addEventListener('dragover', (e)=>{
    console.log("dragOver:-------------")
  })
  fireEvent.dragStart(node, {dataTransfer: {dropEffect: 'move'}})
  fireEvent.dragOver(node, {dataTransfer: {dropEffect: 'move'}})
})

@electroluxcode electroluxcode changed the title fix: mock brower event about https://github.com/testing-library/dom-testing-library/issues/1327 fix: mock brower event about issues 1327 Jul 15, 2024
Copy link

codesandbox-ci bot commented Jul 15, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5cda1a3:

Sandbox Source
react-testing-library-examples Configuration

@electroluxcode electroluxcode marked this pull request as draft July 20, 2024 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fireEvent.drop API behaves not as expected about preventDefault in Browser and js env
1 participant