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
jestのspyOnでmockする際に詰まった話
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
riku0202
July 20, 2022
Programming
0
1.9k
jestのspyOnでmockする際に詰まった話
riku0202
July 20, 2022
Tweet
Share
More Decks by riku0202
See All by riku0202
ReactでWebsocket通信してみた.pdf
riku0202
0
120
Other Decks in Programming
See All in Programming
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
2.6k
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.6k
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
210
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
210
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
250
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
660
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
140
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
790
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
220
MUSUBIXとは
nahisaho
0
140
Apache Iceberg V3 and migration to V3
tomtanaka
0
170
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
65
ラッコキーワード サービス紹介資料
rakko
1
2.3M
Claude Code のすすめ
schroneko
67
210k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1.1k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
310
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7k
Unsuck your backbone
ammeep
671
58k
Ruling the World: When Life Gets Gamed
codingconduct
0
150
The Cult of Friendly URLs
andyhume
79
6.8k
Transcript
jestのspyOnでmockする際に 詰まった話
自己紹介
Riku Shimojima 株式会社HRBrain フロントエンド(React,TS) バックエンド(Go) エンジニア歴1年半 twitter: @Riku_0202_
ある日、CustomHooksのテストを書いていると、、、
なぜかテストが通らない、、、
なぜかテストが通らない、、、 例
なぜかテストが通らない、、、 例
refを渡したElementの 高さを取得し保持する CustomHook 例
例 てすと
useRefのモックが上手くいってないっぽい??
None
調べてみた👀
jestのissueにめっちゃ書いてありました
問題はこのimport方法にありました import * as React from "react"; import React from
"react";
トランスパイル import { useRef } from "react" import * as
React from "react" useRef React.useRef import React from "react" React.useRef
_react.useRef _react.useRef トランスパイル import { useRef } from "react" import
* as React from "react" useRef React.useRef import React from "react" React.useRef _react["default"].useRef
↑は _react["default"] をmockしている jest.spyOn(React, "useRef");
↑は _react["default"] をmockしている jest.spyOn(React, "useRef"); 故に単一importしたuseRefは モックされない _react.useRef; _react["default"].useRef;
None
成功!
[ 参考リンク ] Mock/Spy exported functions within a single module
in Jest jest.spyOnで差し替わってなかった Jest spyOn() calls the actual function instead of the mocked
フロントエンドエンジニアを積極採用募集中です
フロントエンドエンジニアを積極採用募集中です @Riku_0202_
ありがとうございました!! @Riku_0202_