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
260
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
再実装 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
490
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.7k
Other Decks in Programming
See All in Programming
OSもどきOS
arkw
0
590
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
740
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
750
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
230
New "Type" system on PicoRuby
pocke
1
1k
スマートグラスで並列バイブコーディング
hyshu
0
260
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.5k
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
300
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
280
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
610
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
400
Featured
See All Featured
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
250
Automating Front-end Workflow
addyosmani
1370
210k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
200
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
66
55k
エンジニアに許された特別な時間の終わり
watany
107
250k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
310
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
220
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/
おしまい