$30 off During Our Annual Pro Sale. View Details »
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
認証・認可の基本を学ぼう後編
kouyuume
0
250
tparseでgo testの出力を見やすくする
utgwkk
2
290
Graviton と Nitro と私
maroon1st
0
140
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
310
JETLS.jl ─ A New Language Server for Julia
abap34
2
460
Canon EOS R50 V と R5 Mark II 購入でみえてきた最近のデジイチ VR180 事情、そして VR180 静止画に活路を見出すまで
karad
0
140
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
410
PC-6001でPSG曲を鳴らすまでを全部NetBSD上の Makefile に押し込んでみた / osc2025hiroshima
tsutsui
0
190
LLM Çağında Backend Olmak: 10 Milyon Prompt'u Milisaniyede Sorgulamak
selcukusta
0
140
ローカルLLMを⽤いてコード補完を⾏う VSCode拡張機能を作ってみた
nearme_tech
PRO
0
180
Cell-Based Architecture
larchanjo
0
140
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
8
3.4k
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
39
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.8k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
170
30 Presentation Tips
portentint
PRO
1
180
Evolving SEO for Evolving Search Engines
ryanjones
0
77
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
680
Java REST API Framework Comparison - PWX 2021
mraible
34
9k
KATA
mclloyd
PRO
33
15k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
34k
SEO for Brand Visibility & Recognition
aleyda
0
4.1k
Designing Powerful Visuals for Engaging Learning
tmiket
0
190
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_