Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
jestのspyOnでmockする際に詰まった話
Search
riku0202
July 20, 2022
Programming
1.9k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
jestのspyOnでmockする際に詰まった話
riku0202
July 20, 2022
More Decks by riku0202
See All by riku0202
ReactでWebsocket通信してみた.pdf
riku0202
0
130
Other Decks in Programming
See All in Programming
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.3k
Findy - エンジニア向け会社紹介/Findy Company Deck
findyinc
6
400k
ChromeでローカルLLM
ryu1013
0
140
Jetpack Compose Mechanisms
skydoves
3
820
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.1k
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
320
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
sbt 2.0: takeoff
eed3si9n
0
160
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
380
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
270
AWSに止められる覚悟してますか?
morizo_1984
2
540
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
Featured
See All Featured
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
930
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
Building Flexible Design Systems
yeseniaperezcruz
330
41k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Designing for Timeless Needs
cassininazir
1
530
The Curious Case for Waylosing
cassininazir
1
570
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
GitHub's CSS Performance
jonrohan
1033
470k
The Cult of Friendly URLs
andyhume
79
7k
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_