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
riku0202
July 20, 2022
Programming
0
1.8k
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
gunshi
kazupon
1
120
Context is King? 〜Verifiability時代とコンテキスト設計 / Beyond "Context is King"
rkaga
10
1.4k
チームをチームにするEM
hitode909
0
400
AIコーディングエージェント(Manus)
kondai24
0
220
DevFest Android in Korea 2025 - 개발자 커뮤니티를 통해 얻는 가치
wisemuji
0
170
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
140
TestingOsaka6_Ozono
o3
0
180
Navigation 3: 적응형 UI를 위한 앱 탐색
fornewid
1
470
Developing static sites with Ruby
okuramasafumi
0
330
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
280
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
220
Rubyで鍛える仕組み化プロヂュース力
muryoimpl
0
200
Featured
See All Featured
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
93
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
94
Thoughts on Productivity
jonyablonski
73
5k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
710
How GitHub (no longer) Works
holman
316
140k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
70
Building Adaptive Systems
keathley
44
2.9k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
20
Applied NLP in the Age of Generative AI
inesmontani
PRO
3
2k
The SEO Collaboration Effect
kristinabergwall1
0
310
Fireside Chat
paigeccino
41
3.8k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
31
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_