Documentation lacks information on createEvent()
维护者通常 4 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 52/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, react
- 领域
- documentation, testing
调研方向
首先查看 createEvent() 文档和提供的 beforeinstallprompt 示例,包括使用 Object.defineProperties 的临时解决方案。使用清晰、具体的事件创建示例更新文档,并验证该示例涵盖自定义事件属性以及使用 fireEvent() 进行分发。
由索引模型根据 Issue 内容生成。
描述
@testing-library/domversion: latest- Testing Framework and version: jest 26.0.0
- DOM Environment: jsdom latest
Relevant code or config:
import * as React from 'react'
import {render, screen, createEvent, fireEvent, act} from '@testing-library/react'
import {App} from '../index'
test('renders true when event has been fired', async () => {
render(<App />)
await act(async () => {
const event = createEvent('beforeinstallprompt', window, {
userChoice: new Promise((res) =>
res({outcome: 'accepted', platform: ''}),
),
prompt: () => new Promise((res) => res(undefined)),
})
fireEvent(window, event)
})
expect(screen.queryByText(/false/i)).not.toBeInTheDocument()
})
export function App() {
const [eventHeard, setEventHeard] = useState(false)
useEffect(() => {
const evt = (e) => {
e.preventDefault()
setEventHeard(true)
}
window.addEventListener('beforeinstallprompt', evt)
return () => window.removeEventListener('beforeinstallprompt', evt)
})
return <h1>{JSON.stringify(eventHeard)}</h1>
}
What you did:
I was trying to mock the beforeinstallprompt event using createEvent(). The documentation wasn't very clear as to how I create events, so I took a look at the source and it still wasn't clear to me.
What happened:
Reproduction:
Problem description:
Suggested solution:
Update the documentation with examples of exactly how to create events.
Interim solution:
use Object.defineProperties and assign the properties that you need to the object.
const event = createEvent('beforeinstallprompt', window);
Object.defineProperties(event, {
userChoice: {
value: new Promise((res) =>
res({ outcome: 'accepted', platform: '' })
),
},
prompt: { value: () => new Promise((res) => res(undefined)) },
});
fireEvent(window, event);
- 主要语言
- JavaScript
- 星标
- 479
- 派生
- 738
- 平均合并
- 5 天 1 小时
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
testing-library/testing-library-docs 的其他 Issue
-
Broken Chrome Extension Link in Queries Docs可能已有人在做 @rajanpanth 于 60 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 72/100
testing-library/testing-library-docs#1499 ·
维护者通常 4 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
testing-library/testing-library-docs#1528 ·
维护者通常 4 天内回复
-
Framework wrappers and DOM testing library可能已有人在做 @jacklaurencegaray 于 422 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 38/100
testing-library/testing-library-docs#1493 · 3 条评论 ·
维护者通常 4 天内回复
-
难度 2/5 1-3 小时 新手友好度 55/100
testing-library/testing-library-docs#1486 · 1 个 reaction ·
维护者通常 4 天内回复
-
难度 2/5 1-3 小时 新手友好度 48/100
testing-library/testing-library-docs#1485 · 1 条评论 ·
维护者通常 4 天内回复
查看 testing-library/testing-library-docs 的全部 Issue
相似的 Issue
-
area:install bug needs-triage
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
[BUG]: Prompt compressor crashes with TypeError when a past chat has a non-string response.text可能已有人在做 @ManojDevarajulu 今天认领。 未关闭possible bug
难度 2/5 1-3 小时 新手友好度 82/100
Mintplex-Labs/anything-llm#6737 ·
维护者通常 1 天内回复
-
check:passed feeds:add
难度 2/5 1 小时以内 新手友好度 62/100
-
Remove the dead tree 'loadfail' handler in browser.js, which calls a non-existent tree.isSelected()未关闭Housekeeping
难度 2/5 1-3 小时 新手友好度 72/100
pgadmin-org/pgadmin4#10601 ·
维护者通常 1 天内回复