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
0
200
再実装 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
450
Hydrogenで 2022年〜を感じる
nozaki
0
610
microCMSでimgixに入門する
nozaki
0
1.1k
Jamstack Conf 2021を見てブログ構成を見直した話
nozaki
1
1.3k
ユーザーが編集中の状態管理について考えよう
nozaki
3
6.8k
はじめてのUniversal JavaScript
nozaki
1
2.3k
Other Decks in Programming
See All in Programming
GoのGenericsによるslice操作との付き合い方
syumai
3
690
ASP.NETアプリケーションのモダナイズ インフラ編
tomokusaba
1
410
ニーリーにおけるプロダクトエンジニア
nealle
0
490
童醫院敏捷轉型的實踐經驗
cclai999
0
190
FormFlow - Build Stunning Multistep Forms
yceruto
1
190
Cline指示通りに動かない? AI小説エージェントで学ぶ指示書の書き方と自動アップデートの仕組み
kamomeashizawa
1
580
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
1
120
PHPでWebSocketサーバーを実装しよう2025
kubotak
0
160
Composerが「依存解決」のためにどんな工夫をしているか #phpcon
o0h
PRO
1
230
Code as Context 〜 1にコードで 2にリンタ 34がなくて 5にルール? 〜
yodakeisuke
0
100
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
250
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
330
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
Scaling GitHub
holman
459
140k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
How to Ace a Technical Interview
jacobian
277
23k
Done Done
chrislema
184
16k
Building an army of robots
kneath
306
45k
VelocityConf: Rendering Performance Case Studies
addyosmani
330
24k
Agile that works and the tools we love
rasmusluckow
329
21k
Being A Developer After 40
akosma
90
590k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
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/
おしまい