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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ryusou
December 07, 2022
Programming
0
230
再実装 React Testing Library
Saitama.js vol.4でのLTです。
React Testing Libraryのassert関数を少しだけ自作してみました。
Ryusou
December 07, 2022
Tweet
Share
More Decks by Ryusou
See All by Ryusou
Astro 3.0入門
nozaki
0
470
Hydrogenで 2022年〜を感じる
nozaki
0
640
microCMSでimgixに入門する
nozaki
0
1.2k
Jamstack Conf 2021を見てブログ構成を見直した話
nozaki
1
1.4k
ユーザーが編集中の状態管理について考えよう
nozaki
3
7k
はじめてのUniversal JavaScript
nozaki
1
2.5k
Other Decks in Programming
See All in Programming
AIコーディングの理想と現実 2026 | AI Coding: Expectations vs. Reality 2026
tomohisa
0
500
CSC307 Lecture 10
javiergs
PRO
1
690
その「common」ディレクトリ、腐っていませんか?
kinocoboy2
1
110
Go1.26 go fixをプロダクトに適用して困ったこと
kurakura0916
0
250
株式会社 Sun terras カンパニーデック
sunterras
0
1.8k
Package Management Learnings from Homebrew
mikemcquaid
0
270
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
2k
nilとは何か 〜interfaceの構造とnil!=nilから理解する〜 / Understanding nil in Go Interface Representation and Why nil != nil
kuro_kurorrr
2
980
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
2
850
15年目のiOSアプリを1から作り直す技術
teakun
0
490
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
280
AI & Enginnering
codelynx
0
140
Featured
See All Featured
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
120
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.1k
It's Worth the Effort
3n
188
29k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
140
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
91
Balancing Empowerment & Direction
lara
5
920
How to Ace a Technical Interview
jacobian
281
24k
Why Our Code Smells
bkeepers
PRO
340
58k
How Software Deployment tools have changed in the past 20 years
geshan
0
32k
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/
おしまい