Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Documentation lacks information on createEvent()

オープン
#798 コメント 3 件 リアクション 3 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
52/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript, react

調査の方向性

まず、createEvent() のドキュメントと、Object.defineProperties を使った暫定的な解決策を含む、提供されている beforeinstallprompt の例を確認します。明確で具体的なイベント作成の例を追加してドキュメントを更新し、その例がカスタムイベントプロパティと fireEvent() によるディスパッチを扱っていることを確認します。

索引モデルが issue の本文から書いたものです。

説明

  • @testing-library/dom version: 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時間
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

testing-library/testing-library-docs のほかの issue

testing-library/testing-library-docs の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。