並び順

ブックマーク数

期間指定

  • から
  • まで

161 - 200 件 / 302件

新着順 人気順

Jestの検索結果161 - 200 件 / 302件

  • Jest の test.each で Parameterized test を実行する

    Jest で関数の引数を複数パターンチェックしたい場合、ベタに書く方法のほかに、test.each でテーブルとして記述する方法があります。テストの視認性が良くなるため、オススメの記法です。今回はこちらをご紹介するとともに、いくつかの実践問題も提示します。 Jest の test.each とは Jest で Parameterized test を行うことができるメソッドです。関数の「引数と期待値」を複数個与えることができ、Jest はそれをとりかえながら、すべて実行してくれます; test.each([ [1, 1, 2], [1, 2, 3], [2, 1, 3], ])(".add(%i, %i)", (a, b, expected) => { expect(a + b).toBe(expected); }); 上記のような形で、配列によってパラメータを指定することができるようにな

      Jest の test.each で Parameterized test を実行する
    • Matcherを使用する · Jest

      Jest では、マッチャー ("matcher") を使用して、様々な方法で値のテストをすることができます。 このドキュメントでは、よく使われるマッチャーをいくつか紹介します。 マッチャーの完全なリストについては、expect API ドキュメントをご覧ください。 一般的なマッチャー​ 値をテストする最も簡単な方法は、厳密に等価であることです。 test('two plus two is four', () => { expect(2 + 2).toBe(4); }); このコードでは、expect(2 + 2) は "expectation" オブジェクトを返します。 マッチャーを利用しなければこれらの "expectation" オブジェクトは大きな効果を発揮しません。 このコードでは、 .toBe(4) はマッチャーです。 Jestが実行されると、失敗したマッチャーをすべて追跡し、素

        Matcherを使用する · Jest
      • jestでパラメータ化テストをする - Qiita

        module.exports = () => { const hours = new Date().getHours(); return ((6 < hours) && (hours <= 18)); } const isDaytime = require('./isDaytime'); beforeEach(() => { jest.clearAllMocks(); }); const OriginalDate = Date; // 退避 test.each([ [0, false], [5, false], [6, false], [7, true], [17, true], [18, true], [19, false], ])('%i時のとき、%pを返す', (hours, expected) => { jest.spyOn(global, 'Date').mockImplemen

          jestでパラメータ化テストをする - Qiita
        • Release v30.0.0-alpha.1 · jestjs/jest

          Features [jest-config] [BREAKING] Add mts and cts to default moduleFileExtensions config (#14369) [jest-config] [BREAKING] Update testMatch and testRegex default option for supporting mjs, cjs, mts, and cts (#14584) [@jest/core] [BREAKING] Group together open handles with the same stack trace (#13417, & #14543) [@jest/core, @jest/test-sequencer] [BREAKING] Exposes globalConfig & contexts to TestSe

            Release v30.0.0-alpha.1 · jestjs/jest
          • GitHub - swc-project/jest: Super-fast alternative for babel-jest or ts-jest without type checking. Please use main repository for issues

            You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

              GitHub - swc-project/jest: Super-fast alternative for babel-jest or ts-jest without type checking. Please use main repository for issues
            • Jestでテストを書いてみよう(実践編)

              こんにちは、エンジニアのYoheiです。 早速ですが、皆さんはテストコードを書いたことはありますか? テストを書くとなると腰が重くなってしまう方もいるかもしれませんが、実はテストを書くと良いことがたくさんあるんです。 テストについてよくわからない方、これからテストを書き始めるという方はぜひ読んでみてください! 前半は、テストの概要について説明します。 後半は、Javascriptの テスティングフレームワークである Jest を使って実際のコードを例に説明していきます。 まずはテストの概要について簡単に見ていきましょう。 テストとは ※学校でやるテストではありません。 ここでのテストとは、プログラムのテストです。 プログラムのテストとは、実装したプログラムが意図した通りに動いているかを検証するために行うものです。 テストの種類 テストには主に3つの種類が存在し、以下のように分類できます。

                Jestでテストを書いてみよう(実践編)
              • Enhance Jest configuration with Module Aliases

                You can find the content of this article updated to the most recent version of vue-test-utils and Jest on my book. The module managers we have in the JavaScript community, mainly ES Modules and CommonJS, don't support project-based paths. They only support relative paths for our own modules, and paths for the node_modules folder. When a project grows a bit, it's common to see paths such:

                  Enhance Jest configuration with Module Aliases
                • Doubling down on local development with Workers: Miniflare meets workerd

                  Doubling down on local development with Workers: Miniflare meets workerd11/18/2022 Local development gives you a fully-controllable and easy-to-debug testing environment. At the start of this year, we brought this experience to Workers developers by launching Miniflare 2.0: a local Cloudflare Workers simulator. Miniflare 2 came with features like step-through debugging support, detailed console.lo

                    Doubling down on local development with Workers: Miniflare meets workerd
                  • Next.js + TypeScriptのプロジェクトにJestを導入する - Qiita

                    この記事の概要 Next.js + TypeScriptのプロジェクトにJestを導入する手順を解説した記事です。 対象読者 Next.jsを触った事がある人 TypeScriptの基礎的な知識がある人 Jestについて基礎的な知識がある人 この記事を書こうと思った動機 最近Next.jsで個人開発を始めました。 Next.jsはReactベースのフレームワークです。 Reactの create-react-app に似たcreate next-appというコマンドがあります。(プロジェクトのテンプレートを自動生成するツールです) ただしReactの create-react-app と違ってテスト実行環境は用意されていません。 そこでJESTを導入する手順を残しておきます。 実行環境 Node.js 14.15.3 Next.js 11.1.2 React 17.0.2 具体的な手順とゴ

                      Next.js + TypeScriptのプロジェクトにJestを導入する - Qiita
                    • Jest 27: New Defaults for Jest, 2021 edition ⏩ · Jest

                      In the Jest 26 blog post about a year ago, we announced that after two major releases with few breaking changes, Jest 27 will flip some switches to set better defaults for projects that are new or can migrate smoothly. This gives us the opportunity to remove some packages from the default distribution of Jest 28 and publish them as separately installable and pluggable modules instead. Everyone on

                        Jest 27: New Defaults for Jest, 2021 edition ⏩ · Jest
                      • Jestの設定 · Jest

                        Jestの哲学はデフォルトでうまく動作することですが、時にはより細かい設定が必要になることもあります。 設定は、専用の JavaScript、TypeScript、または JSON ファイルで定義することをおすすめします。 ファイル名が jest.config.js|ts|mjs|cjs|json の場合、ファイルは自動的に発見されます。 --config フラグを使用すると、ファイルに明示的なパスを渡すことができます。

                          Jestの設定 · Jest
                        • GitHub - EvHaus/test-runner-benchmarks: A repository to measure performance of various JavaScript test runners

                          You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert

                            GitHub - EvHaus/test-runner-benchmarks: A repository to measure performance of various JavaScript test runners
                          • TypeScript: JestでES Modulesは問題なくテストできるのか?

                            TypeScript + Node.js + ESM + Jestの組み合わせを調査する。 調査すること ES Modulesをts-jestで問題なく実行できるか? 実験コード 実験のために書いたコードはGitHubに置いてある suinplayground/typescript-nodejs-esm-jest

                              TypeScript: JestでES Modulesは問題なくテストできるのか?
                            • Storybook 単体でインタラクションテストを実施する

                              Storybook の Component Story Format 3.0 では新機能として play() 関数が追加されました。 play() 関数は Storybook 上でユーザーのクリックやフォーム入力のようなインタラクションな操作を表現できます。 以前は composeStories() 関数により Storybook 上で作成したストーリーを Jest で再利用する方法を書いたのですが、どうやら Storybook のみで完結してテストを実行できるようですのでこちらを試してみます。 Vite プロジェクトの作成 まずは以下コマンドで Vite プロジェクトを作成します。 $ npm init vite@latest my-vue-app -- --template vue-ts $ cd my-vue-app $ npm install Storybook のインストール 続

                                Storybook 単体でインタラクションテストを実施する
                              • Jest を使用した単一ファイルコンポーネントのテスト | Vue Test Utils

                                # Jest を使用した単一ファイルコンポーネントのテスト このセットアップのサンプルプロジェクトは、 GitHub にあります。 Jest は Facebook が開発したテストランナであり、ユニットテストソリューションの提供を目指しています。 Jest の詳細については、公式ドキュメント を参照してください。 # Jest のセットアップ 既に、webpack、vue-loader、および Babel が正しく設定されている設定から始めると仮定します。例: vue-cli によって雛形生成された webpack-simple テンプレートです。 まず Jest と vue-test-utils をインストールします:

                                • Mocking a JavaScript Class with Jest, Two Ways to Make it Easier

                                  Mocking a JavaScript Class with Jest, Two Ways to Make it Easier

                                    Mocking a JavaScript Class with Jest, Two Ways to Make it Easier
                                  • Jest 29: Snapshot format changes · Jest

                                    Jest 29 is here, just a few short months after Jest 28. As mentioned in the Jest 28 blog post, this version contains just a couple of breaking changes, in order to make the upgrade as smooth as possible. The only breaking changes that should be noticeable are: Node versions 12 and 17 are dropped, both of which are EOL The snapshotFormat property is changed to: + snapshotFormat: { + escapeString: f

                                      Jest 29: Snapshot format changes · Jest
                                    • Release v29.6.0 · jestjs/jest

                                      Features [jest-circus, jest-snapshot] Add support for snapshot matchers in concurrent tests (#14139) [jest-cli] Include type definitions to generated config files (#14078) [jest-snapshot] Support arrays as property matchers (#14025) [jest-core, jest-circus, jest-reporter, jest-runner] Added support for reporting about start individual test cases using jest-circus (#14174) Fixes [jest-circus] Preve

                                        Release v29.6.0 · jestjs/jest
                                      • ファイル直下でexportされている関数にjest.spyOnを使いたい | DevelopersIO

                                        こんにちは。サービスGの金谷です。 JestにはspyOnという便利なメソッドが用意されています。 Jestオブジェクト · Jest これを使うとJestでのテスト時に指定したメソッドがコールされているかどうかを確認できたりします。 具体的な使い方のイメージは先輩が書かれているこちらの記事が参考になると思います。 jest.spyOn() で Vue.js コンポーネントからのサービス呼び出しをテストする 公式ドキュメントを見ると第一引数にObject、第二引数にメソッド名(文字列)を受け取ると書かれています。 jest.spyOn(object, methodName) では、オブジェクトのメソッドではない、ファイル直下でexportされている関数にはどう使ったらいいの・・・? と思ったので調べてみました。 以下のようなコードを想定します。 helloWorldService.ts e

                                          ファイル直下でexportされている関数にjest.spyOnを使いたい | DevelopersIO
                                        • Jest Mock User Module in All Test Files

                                          Is there a way to make it so that jest always mocks my modules so I don't need to include it in all my jest tests? Currently I have a config file // src/__mocks__/config.js export default { dbConfig: 'TestDBConfiguration' }; // src/config.js export default { dbConfig: ... // Some other stuff }; To run my unit tests I have to use the mocked config.js. Currently in all my unit tests I have to includ

                                            Jest Mock User Module in All Test Files
                                          • From v27 to v28 · Jest

                                            Upgrading Jest from v27 to v28? This guide aims to help refactoring your configuration and tests. Compatibility​The supported Node versions are 12.13, 14.15, 16.10 and above. If you plan to use type definitions of Jest (or any of its packages), make sure to install TypeScript version 4.3 or above. Configuration Options​extraGlobals​The extraGlobals option was renamed to sandboxInjectedGlobals:

                                              From v27 to v28 · Jest
                                            • はじめてのJEST入門:週末ライフ

                                              JavaScriptのテストフレームワークであるJestの入門書です。 Jestのインストールから基本的なアサーション、モック化、UIテストからE2EテストやCIツールの導入など実践的な使い方まで紹介しています。Jestはユニットテストに必要な機能をほぼ網羅しているため、これからNode.jsやJavaScriptのテスト書き始める人には最適なテストフレームワークです。ぜひ本書を通じてJestを利用してテストを書くことの手軽さやテストの有用性を知って頂ければ幸いです。 本書では、まだJestを使ったことがない、テストを書いたことがないという方でも、1つずつ試しながら読み進めることができます。 また、サンプルコードも充実しており、本書のコードはすべてGithubのリポジトリからダウンロードすることができます。 ■ 目次 1. はじめに 2. Jestとは? 3. Jestのインストールとはじ

                                                はじめてのJEST入門:週末ライフ
                                              • Release v29.6.3 · jestjs/jest

                                                Fixes [expect, @jest/expect-utils] ObjectContaining support symbol as key (#14414) [expect] Remove @types/node from dependencies (#14385) [jest-core] Use workers in watch mode by default to avoid crashes (#14059 & #14085). [jest-reporters] Update istanbul-lib-instrument dependency to v6. (#14401) [jest-mock] Revert #13692 as it was a breaking change (#14429) [jest-mock] Revert #13866 as it was a b

                                                  Release v29.6.3 · jestjs/jest
                                                • Vue Test setMethodsのdeprecated対策

                                                  setMethodsは公式で非推奨とされてる件 前に書いた記事にも言及しましたけどコンポーネントのメソッドをテストしたい場合よくsetMethodで該当メソッドをmockとしてテストしますが、下記のようなコードはよく見る例です。 // stubはmock関数(メソッド) const stub = jest.fn(); wrapper.setMethods({ // executeSearchはテストしたいメソッドで、mock関数をアサインします executeSearch: stub, }); ただ公式は非推奨なので、テストケースとしては実行してもパスしますが、warningエラーが出てくるから鬱陶しいですね... Orz 今回はsetMethodsを使わずにメソッドをテストする方法を紹介します。 今回のシナリオ リンクをクリックして、exeSearchが正しく発火されたどうかテストしたい

                                                    Vue Test setMethodsのdeprecated対策
                                                  • Jestでnode-fetchをmockする - Qiita

                                                    Jestでnode-fetchをmockする方法についてまとめます。 Jestのmock機能を利用する方法は、「Node.jsのテストでJestを使ってfetchをモックするのは意外に大変」を参照してください。ここでは、mock-fetchおよびjest-fetch-mockを利用する方法について説明します。 mock-fetchやjest-fetch-mockを利用することで、node-fetchを簡単にmockでき、呼び出しの確認も容易になります。 mock-fetchおよびjest-fetch-mockはfetchおよびnode-fetch (isomorphic-fetchも) をmockできますが、ブラウザ上のfetchをmockすることを想定しているため、node-fetchをmockするにはひと手間必要となっています。 mock-fetchを利用する方法 mock-fetch

                                                      Jestでnode-fetchをmockする - Qiita
                                                    • How To Mock Fetch in Jest

                                                      Making HTTP requests in tests isn't a great idea in most situations... it can slow your tests down, is unreliable, and the API you are making requests to may not appreciate it either. So how do you avoid making HTTP requests in your tests? If you are using fetch, you're in the right place, if you are using Axios, head on over here. We're going to be mocking fetch calls today in our Jest tests, sta

                                                        How To Mock Fetch in Jest
                                                      • Software tests as a documentation tool

                                                        Why tests are perfect to tell a story of your code I'm working on a big UI Testing Best Practices project on GitHub, I share this post to spread it and have direct feedback. Documenting is generally hard, it requires precise and meticulous work and it requires that all the members of the team understand and value writing good documentation. Documenting is selfless work and for selfless, I mean tha

                                                          Software tests as a documentation tool
                                                        • Jestを実行した時に、同時にESlintを走らせてみる - RAKSUL TechBlog

                                                          こんにちは。印刷のラクスルでフロントエンドを担当している菅野です。 今回はJestで単体テストを実行した際、同時にESlintも走らせるための設定をご紹介します。 TL; DR jest-runner-eslintというパッケージを導入した Jestでの単体テスト実行と同時に、テストファイルに対してlintをかけるようにした autofixもするようにした やりたかったこと テスト実行(npm run test)と同時に、テストファイルにのみlintを実行したい lintのために別scriptを実行は、あまりしたくない Jestと連携させたい ついでにautofixもさせたい(npm run lint --fix相当) 前提条件 Jestが導入されていること ESlintが導入されていること(.eslintrcがプロジェクトに存在すること) 動作環境 今回、jest-communityで公

                                                          • RailsのSPAにJestを導入してみた話 - Qiita

                                                            この記事の内容 業務で、RailsのSPAを作っています。フロントのテストフレームワークとしてJestを導入することになり、チームで探りつつ実装したので、その記録をまとめたいと思います。 なお、各種バージョンは以下の通りです。 Rails ... 6.1.0 Jest ... 27.4.7 node.js ... 14.19.0 必要なライブラリの導入 必要なライブラリを導入します。TypeScriptを使用していたので、Jestだけではなく @type/jest も必要でした。

                                                              RailsのSPAにJestを導入してみた話 - Qiita
                                                            • Release v10.8.0 · TypeStrong/ts-node

                                                              Questions about this release? Ask in the official discussion thread: #1767 Added Added support for module=NodeNext, module=Node16, .mts, .cts, .mjs, and .cjs file extensions (#1414, #1694, #1744, #1745, #1727, #1717, #1753, #1757) @cspotcode For best results, enable experimentalResolver (docs) See TypeScript's official documentation: https://www.typescriptlang.org/docs/handbook/esm-node.html enabl

                                                                Release v10.8.0 · TypeStrong/ts-node
                                                              • VSCode上でNode.js Jestでdebug(デバッグ)をするための設定をしてみた |SHIFT Group 技術ブログ

                                                                はじめにこんにちは、SHIFTの開発部門に所属している Katayama です。 VSCode 上で Node.js(ES6 で実装)の debug をするための設定をしてみたでは VSCode 上で Node.js(ES6 で実装したもの)のデバッグを行うための設定を行ってみた。 今回は Jest でテストを実行する際に、同じように VSCode 上でデバッグするための設定をやってみたいと思う。 以下で見ていくように、やり方は 2 つあるので、それぞれについてみていきたいと思う。 ①VSCode の Extensions(拡張機能)を利用する ②VSCode の組み込みデバッガを使用する設定を launch.json に行いデバッグする ※ES6(ES Modules を利用した)コードで Jest によるテストを実行する方法はNode.js(ES6 で実装)で Jest によるテストを

                                                                  VSCode上でNode.js Jestでdebug(デバッグ)をするための設定をしてみた |SHIFT Group 技術ブログ
                                                                • React Router: Declarative Routing for React

                                                                  Learn once, Route Anywhere

                                                                    React Router: Declarative Routing for React
                                                                  • Absolute paths (baseUrl) gives error: Cannot find module

                                                                    I am setting a configuration to run my tests in a create-react-app + typescript app (from which I have ejected). I am using jest + enzyme. In my tsconfig.json I have set baseUrl='./src' so I can use absolute paths when I import modules. For example this is a typical import statement in one of my files: import LayoutFlexBoxItem from 'framework/components/ui/LayoutFlexBoxItem'; You can see that the

                                                                      Absolute paths (baseUrl) gives error: Cannot find module
                                                                    • Release v29.7.0 · jestjs/jest

                                                                      Features [create-jest] Add npm init / yarn create initialiser for Jest projects (#14465) [jest-validate] Allow deprecation warnings for unknown options (#14499) Fixes [jest-resolver] Replace unmatched capture groups in moduleNameMapper with empty string instead of undefined (#14507) [jest-snapshot] Allow for strings as well as template literals in inline snapshots (#14465) [@jest/test-sequencer] C

                                                                        Release v29.7.0 · jestjs/jest
                                                                      • Use test.todo() when writing Jest tests.

                                                                        When I start building a new component, I can sometimes completely forget to write tests as I am going, or perhaps I've finished writing my component, and I don't fully remember what I should be writing in my test suite. A quick solution to this if you are using Jest is to build your test suite, and replace your tests with test TODOS! describe('NewsContent', () => { it('Should render a normal strin

                                                                          Use test.todo() when writing Jest tests.
                                                                        • JestでspyOn関数を使って、windowをモックする方法 | Tech Q Lab - 株式会社キューのテックブログ

                                                                          はじめにこんにちは、Webエンジニアの柴田です。 今回はJestでwindowをモックする方法をご紹介します。 windowをモックすることで、windowを使ったスクロールのテストやwindowのリサイズのテストなどが可能になります。 環境Jest: 27.5.1 TypeScript: 4.6.4 実装jest.spyOnについて元の関数の実装をモック関数で上書きするだけでなく、元の実装を残したまま、対象の関数を監視することができる関数です。 jest.spyOnを使ってwindowをモックまず、windowをモックする変数を定義します。 モック方法はJestのspyOn関数を使います。 // 第三引数が'get'の理由は、windowオブジェクトのgetメソッドをモックしたいため const windowSpy = jest.spyOn(window, 'window', 'get'

                                                                            JestでspyOn関数を使って、windowをモックする方法 | Tech Q Lab - 株式会社キューのテックブログ
                                                                          • CompositionAPIを使ってcomposition functionを分離した状態でテストする - Qiita

                                                                            10/27 Vue-next版をこちらに書きました!この記事はVue 2.0用の記事です。 最初に ついにComposition APIがrfc上でmergeされました rfc上でmergeされたこともあって、本格的に触っていく人も増えていくのではないか、と思います。 Composition APIを使うことで型推論がよくなる、IDEの恩恵を受けやすいだけでなく、 少し工夫するだけでなんちゃってSingle Store patternなどができたりします。 しかしながら、Composition API自体が新しい、ということもあってテストに関する情報がほとんどありません。 そこで、今回はComposition Functionを分離した状態でのテストの書き方について説明します。 Composition Functionを分離するって? 公式DocumentだとLogic reuse cod

                                                                              CompositionAPIを使ってcomposition functionを分離した状態でテストする - Qiita
                                                                            • How to mock useRouter? · Issue #7479 · vercel/next.js

                                                                              You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert

                                                                                How to mock useRouter? · Issue #7479 · vercel/next.js
                                                                              • Going too far with Jest Custom Matchers in TypeScript

                                                                                Going too far with Jest Custom Matchers in TypeScriptDear future me, and other people who land here trying to copy-paste a matcher. Here’s the gist for you. I needed a Jest custom matcher a few days ago, and I couldn’t find any article I could copy-paste it from. The docs are okay, and they even mention how to use custom matchers in TypeScript, but I think I have some observations which are not in

                                                                                • Unable to change window.location using Object.defineProperty · Issue #5124 · jestjs/jest

                                                                                  You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert

                                                                                    Unable to change window.location using Object.defineProperty · Issue #5124 · jestjs/jest