Documentation lacks information on createEvent()
Maintainer thường phản hồi trong vòng 4 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 52/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, react
- Lĩnh vực
- documentation, testing
Hướng nghiên cứu
Bắt đầu bằng việc xem lại tài liệu về createEvent() và các ví dụ beforeinstallprompt được cung cấp, bao gồm giải pháp tạm thời với Object.defineProperties. Cập nhật tài liệu bằng các ví dụ rõ ràng, cụ thể về việc tạo sự kiện và xác minh rằng ví dụ bao quát các thuộc tính sự kiện tùy chỉnh cũng như việc dispatch bằng fireEvent().
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
@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);
- Ngôn ngữ chính
- JavaScript
- Star
- 479
- Fork
- 738
- Merge trung bình
- 5 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của testing-library/testing-library-docs
-
Broken Chrome Extension Link in Queries DocsCó thể đã có người làm @rajanpanth đã nhận 60 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
testing-library/testing-library-docs#1499 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
testing-library/testing-library-docs#1528 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Framework wrappers and DOM testing libraryCó thể đã có người làm @jacklaurencegaray đã nhận 422 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 38/100
testing-library/testing-library-docs#1493 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
testing-library/testing-library-docs#1486 · 1 reaction ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 48/100
testing-library/testing-library-docs#1485 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
Tất cả issue của testing-library/testing-library-docs
Issue tương tự
-
[BUG]: Prompt compressor crashes with TypeError when a past chat has a non-string response.textCó thể đã có người làm @ManojDevarajulu đã nhận hôm nay. Đang mởpossible bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Mintplex-Labs/anything-llm#6737 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add: Tooncast brazil feedĐang mởcheck:passed feeds:add
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 62/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
motiondivision/motion#3935 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
codex-team/editor.js#3037 ·
-
No Code Attached Yet
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
joomla/joomla-cms#48626 ·
Maintainer thường phản hồi trong vòng 1 ngày