まとめJavaScript の callback メソッドを testable にしたい。 testable にするには独立して呼べることが大事。つまり独立メソッドにし、名前をつけることが必要。独立メソッドを callback として渡すにはリファレンスにするリファレンスとして渡されたものは実行時に this が決定するのでそのまま実行すると同じ class 内でも this を見失うリファレンスを bind(this) しておこう例
まとめJavaScript の callback メソッドを testable にしたい。 testable にするには独立して呼べることが大事。つまり独立メソッドにし、名前をつけることが必要。独立メソッドを callback として渡すにはリファレンスにするリファレンスとして渡されたものは実行時に this が決定するのでそのまま実行すると同じ class 内でも this を見失うリファレンスを bind(this) しておこう例
最近 React SFC (Stateless Functional Components) や Redux の影響を受けて、ES.next な環境でもクラスより関数で実装するようにしている。ES Modules であれ Node であれ個別に関数を外部公開できるからクラスを使用せずとも実装には十分だし、むしろ関数を積極的に採用することで外部依存を引数に限定できる。 しかし困ったことが。非公開の関数を単体テストする手段がない。 そもそも非公開なものをテスト対象とするのは悪手では?と言われればそのとおり。しかし公開関数が単一単純でも内部で多くの非公開な関数へ依存しているなら、それらを個別に単体テストしたくなるだろう。外部からみたら公開関数を単体テストしているつもりでも実際には結合テストなわけで。 クラスなら今のところアクセス指定子がないため、非公開メソッドは命名を工夫する慣習 (アンダースコ
この記事は一休.com Advent Calenrad 2017の2日目です。 宿泊事業本部フロントエンドエンジニアの宇都宮です。 一休.comの宿泊予約サービス(以下、一休)では、以下のようなスタックでWebフロントエンドの開発を行っています。 言語:ES 2017 ライブラリ・フレームワーク:古いところはjQuery、新しいところはVue.js ビルドパイプライン:Webpack + Babel 一休では、主要導線のE2Eテストは整備されています*1。一方、フロントエンド(JavaScript)のユニットテストは発展途上といったところです。 本記事では、一休のJSユニットテスト環境の変遷と現状について紹介します。 AVA 2017年4月の時点で、一休のJSユニットテスト環境は以下のような状況でした。 テスティングフレームワーク:AVA Babelでビルドされているコード:1,000行程
この記事は、はてなエンジニアアドベントカレンダー2016の5日目の記事です。 こんにちは、はてなでアプリケーションエンジニアをしている id:shiba_yu36 です。先日、buildersconにおいて、現在所属しているプロジェクトでJavaScriptのユニットテストを導入した知見について、「一から始めるJavaScriptユニットテスト」というタイトルで発表しました。 speakerdeck.com この発表は、実際にJavaScriptのユニットテスト環境を作ってみると非常にハードルが高いと感じたので、そのハードルを少しでも下げられればという思いで、非常にシンプルな例で一から環境を作る例を紹介しました。アジェンダは次のとおりでした。 カクヨムのJS環境 JSのテストツールを整理する 通常の関数のユニットテスト DOM操作する機能のユニットテスト カクヨムのJS環境や、JSのテスト
nodist + v8.0.0 //node v 6.0.0とかだとasync functionが使えないのでv7.0.0以上にすること nodist v8.0.0 node -v //確認 npm install chromeless cd C:\Users\ryo-sato\AppData\Local\Google\Chrome SxS\Application //chromeのパス chrome.exe --romote-debugging-port=9222 --disable-gpu --headless ・C:直下にtmpフォルダを作る //スクリーンショット用 ・C:\nodeのフォルダを作る //スクリプトを置く場所 ・C:\node\testにexsampleスクリプトを記載
if(add(1, 2) == 3) { console.log("テスト結果OK"); } else { console.log("テスト結果NG"); } のように、ひたすら泥臭いコードを書くハメになる可能性があります。(これは極端な例ですが) また、このままではテスト実行後の結果がとても分かり辛いです。 どんなテストに成功したのか/失敗したのか、全体でどれだけテストがあって、どれだけパスしたのか。 はたまた失敗した場合に、どんな部分がNGだったのか。 これらを解決するためにあるのが、テストフレームワークと呼ばれるものです。 Javaで言えばJUnit、RubyではRSpec、PHPではPHPUnitやPHPSpecなどが該当します。 こういったテストフレームワークを使うことで、テストを簡潔に分かりやすく書けるようになります。 また、こんな感じでテスト結果も見やすく出力してくれます。
Alpacaで主にフロントエンドを担当している北山(@gamella, blog)です。 フロントエンドを開発していると、「ログインして、これをクリックしたら、この表示が行われていること」みたいなUIテストを環境非依存で簡単に行いたいと思うことがありますよね?僕はあります。 Alpacaでは開発にDockerを全面採用しているということもあり、最近ちょくちょく目にするNightmareJSをDocker上で動かして簡単にUIテストを導入できたので、その知見を共有したいとおもいます。 Nightmare まず、どうしてDockerを利用したいかということですがAlpacaでは、すべての機能をDocker上で動作させているため、それに倣っているいうこともありますがUIテストをローカルでもCircleCIでも、Dockerが動作する環境であればどこでもコードの改変なしで実施できるというのは大きな
The powerful, easy-to-use JavaScript testing framework.Get Started View the Docs Easy Zero configuration and setup for any Node.js project, and minimal setup for Browser-based projects. Universal QUnit can run anywhere; web browsers, Node, SpiderMonkey, even in a Web Worker! Test your code where it runs.
概要 コマンドはSeleniumに対してどう動くか指示するものです。コマンドにはActionとAccessor、Assertionの三種類があります。 各コマンドの呼び出しは、テストケースのtableにおける以下のような1つの行で表します。 Actionコマンドは、アプリケーションの状態を一般に操作するものです。Actionコマンドは「このリンクをクリックする」とか「あのオプションを選択する」といった動作を行います。動作に失敗するか、エラーが発生した場合は、現在実行中のテストは中止されます。 多くのActionコマンドは"AndWait"サフィックスを付けることができます(例えば"clickAndWait")。このサフィックスはSeleniumに対して、コマンドを実行してサーバへの通信が行われた後に新しいページがロードされるのを待つように指示するものです。 Accessorコマンドは、
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く