DBMS に依存するロジックのテストを書く時、主に2つの手法があると思います。 Repository 層などを mock する Service 層のテストをする時は、その下位の Repository 層を mock して、DBMS に依存しない形にしてからテストする レイヤードなアプリケーションで適用できる手法 テスト実行時もDBMS を裏で動かして、それを使う本番と同じスキーマを持つDBMS に対して、実際に insert したり select してテストするDBMS はdocker-compose upとかで事前に立ち上げておく 双方にそれぞれ良さがあって、プロダクトによってどっちでやるか変わってくると思います。 この記事では 2 の手法を Prisma でどうやるかについて紹介します。 前提 実際のテストコードの例 テストヘルパーを作る 別解: ヘルパーを自動生成する je
I have a file that relies on an exported const variable. This variable is set to true but if ever needed can be set to false manually to prevent some behavior if downstream services requestit. I am not sure how to mock a const variable in Jest so that I can changeits value for testing the true and false conditions. Example: //constants module export const ENABLED = true; //allowThrough module im
React のコンポーネントのテストを書いてたら、テストは成功してるんだけど、こういう感じの Warning が出力されるって場合がある Warning: An update to Counter inside a test was not wrapped in act(...). When testing, code that causesReact state updates should be wrapped into act(...): act(() => { /* fire events that update state */ }); /* assert on the output */ ステートを変更するときは act で囲んでねって書いてある。だから、囲めばいいのかなぁ?って思ってたら、ちょっと触った感じ、どうやらそういうことでもないみたい。ので、うろうろしてたら、この2
Jest can be used to mock ES6 classes that are imported into files you want to test. ES6 classes are constructor functions with some syntactic sugar. Therefore, any mock for an ES6 class must be a function or an actual ES6 class (which is, again, another function). So you can mock them using mock functions. An ES6 Class Example We'll use a contrived example of a class that plays sound files, Sound
テスト環境をJasmineからJestに入れ替えましたので、カバレッジを上げるためおよびTDD的にもこちらの活用を行っていきたいと思います。一年ぐらい、いや二年?、目を離した間にモック機能がかなり成熟していました。 そのまえにeslintreact/jsx-boolean-value 細かい話として、ずっとJSXでBoolean値のプロパティに対してリテラルでtrue / falseを書くとEslintに怒られることに理不尽を感じてましたが、理由と対応を目にして納得しました。 理由:https://facebook.github.io/react/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored JSXでBooleanリテラルは出力されないから。そのため思惑違いのコードを書かせないためにBooleanリテラルをJ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く