Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
再実装 React Testing Library
Search
Ryusou
December 07, 2022
Programming
250
0
Share
再実装 React Testing Library
Saitama.js vol.4でのLTです。
React Testing Libraryのassert関数を少しだけ自作してみました。
Ryusou
December 07, 2022
More Decks by Ryusou
See All by Ryusou
Astro 3.0入門
nozaki
0
480
Hydrogenで 2022年〜を感じる
nozaki
0
650
microCMSでimgixに入門する
nozaki
0
1.2k
Jamstack Conf 2021を見てブログ構成を見直した話
nozaki
1
1.4k
ユーザーが編集中の状態管理について考えよう
nozaki
3
7.1k
はじめてのUniversal JavaScript
nozaki
1
2.6k
Other Decks in Programming
See All in Programming
AlarmKitで明後日起きれるアラームアプリを作る
trickart
0
140
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
770
JCON - Create Agentic AI Apps, The Easy Way!
kdubois
1
110
エラー処理の温故知新 / history of error handling technic
ryotanakaya
7
1.9k
20年以上続くプロダクトでも使い続けられる静的解析ツールを求めて
matsuo_atsushi
0
150
書き換えて学ぶTemporal #fukts
pirosikick
2
370
From Formal Specification to Property Based Test
ohbarye
0
2.6k
t *testing.T は どこからやってくるの?
otakakot
1
940
Programming with a DJ Controller — not vibe coding
m_seki
3
850
2026-04-15 Spring IO - I Can See Clearly Now
jonatan_ivanov
1
210
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
3.1k
PHPer、Cloudflare に引っ越す
suguruooki
2
200
Featured
See All Featured
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
550
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
370
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
280
Designing for Timeless Needs
cassininazir
1
220
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
[SF Ruby Conf 2025] Rails X
palkan
2
1k
Statistics for Hackers
jakevdp
799
230k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
350
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.2k
Fireside Chat
paigeccino
42
3.9k
Transcript
しばらくお待ちください
私について りゅーそう 埼玉県育ちのエンジニアです。 (生まれは千葉なのは内緒...) Saitama.jsの運営しています。 埼玉のおすすめ観光地は権現堂の桜 です
I LOVE 杉戸町 「杉戸天然温泉 雅楽の湯」は日本一 の温泉といっても過言ではない 食事は「高橋屋」で鰻コースを予約 して優勝です。 お子様連れは東武動物公園もあるよ (隣の宮代町だけど...)
画像:https://utanoyu.com/より
ありがとうございました! (今日はこれを伝えにきました)
サンプルのクソアプリ
フォームの(一部の) テストをやっていきます
再実装 React Testing Library
React Testing Library Reactコンポーネントのテストライブラリ https://testing-library.com/docs/react-testing-library/example-intro
None
ASSERTを自作していく💪 https://testing-library.com/docs/react-testing-library/example-intro
再実装 React Testing Library ASSERT編
DEMO InputWithAlert コンポーネント
STEP1:idを使ったテスト
STEP1:idを使ったテスト getByIdを作成する ・idは一意ではならない ・本来は必要のないマークアップ ・テスト書きながら、プロダクト独自 の値を参照するのがとても辛い
STEP2:roleを使ったテスト queryByRoleをつくる ・マークアップも改善する ・id管理がなくなるなど壊れにくいテス トになる ・(ロールの知識があれば)暗黙的にテ ストが書ける
STEP3: a11ty assertion aria-invalidをテストします
STEP3: a11ty assertion a11tyを関数でテスト ・マークアップがa11tyを満たしているかを関 数側で担保できる ・ まとめておくことで一連のinterfation test 的なのが書きやすい(はず...未検証.....)
・Headless UIが行っている
STEP3: a11ty assertion before after -----act----- https://github.dev/tailwindlabs/headlessui
TEST ALL PASS!! LGTM👏👏
None
ライブラリを適切に 使っていこう!
参考 「雅楽の湯公式サイト」 https://utanoyu.com/ 「React Testing Library」 https://testing-library.com 「Headless UI GitHub」
https://github.dev/tailwindlabs/headlessui 「Headless UI」 https://headlessui.com 「React Hook Form」 https://react-hook-form.com/advanced-usage/
おしまい