Panda Noir

JavaScript の限界を究めるブログでした。最近はいろんな分野を幅広めに書いてます。

2022-11-01から1ヶ月間の記事一覧

satisfies は msw でモックを書くときとかに使える

import { setupServer } from 'msw/lib/node'; import { rest } from 'msw'; type ArticleResponse = { title: string; id: string }; setupServer( rest.post('/article', (_req, res, ctx) => res( ctx.json({ title: 'mocked article', id: 'id' } satisf…

@testing-library/react の debug が途中で途切れてしまう問題について

debug の出力には文字数制限があります。それを回避する方法について紹介します。 in short: debug ではなく prettyDOM(baseElement)) を使う const { debug } = render(<HelloWorld />); debug(); ↓ import { prettyDOM } from '@testing-library/react'; const { baseEle</helloworld>…

useRef するとき、Readonly をつけると幸せになれるかもしれない

useRef<Readonly<HTMLElement>>(null) とすれば ref.current.innerHTML = '' などを禁止できる。つまり、setter として ref を使わないという意思表示になる。 まあ、setAttribute とか appendChild は防げないので完璧ではないですが</readonly<htmlelement>