Deleted articles cannot be recovered. Draft of this article would be also deleted. Are you sure you want to delete this article?

1) Calculator null should be a 'null': TypeError: Cannot read property 'should' of null : : 2) Calculator undefined should be an 'undefined': TypeError: Cannot read property 'should' of undefined : : Chains 全てのアサーションはshould.jsラッパーオブジェクトを返ので、チェインすることができる。 「to, be, been, is, that, which, and, has, have, with, at, of, same」はチェイン可能なgetterとして提供されていて、テスト機能は提供していないみたい。 .not アサーションを否定します。 .deep deepフラグを設定
はじめに 最近Reactとか触っています。Github上とかでいろいろなコードを見させていただくのですが、React周辺はReduxを使っているのでBabel使ってるけど、テストはFacebookのJestを使っていてあんまりBabel使えてなかったり、もはやテスト書いてなかったりします。 そもそもReactはフロントエンドのライブラリなので、あまりテストを書きたくなくなるのもわかります。ですが、Railsやっててもなるべくテストを書くことを尊重する雰囲気になってきているので、React周辺でもテストを書いていきたいのです。そこで、JestではなくてMochaとChaiを使ってテストを書くにはどうするべきなのかと思い、まとめました。 環境 node: v5.1.0 npm: 3.3.12 ディレクトリ構成
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <link rel="stylesheet" href="node_modules/should/node_modules/should-format/tests/browser/mocha.css" /> <title>テスト</title> <script type="text/javascript" src="node_modules/chai/chai.js"></script> <script type="text/javascript" src="node_modules/should/node_modules/should-format/tests/browser/mocha.js"></script> <script type="text/javas
export default class RecieveParameter { constructor(e) { const req = JSON.parse(e.postData.contents); const payload = req.payload; this.status = payload.status; this.subject = payload.subject; this.build_url = payload.build_url; this.branch = payload.branch; this.reponame = payload.reponame; this.username = payload.username; } returnParams() { return { status: this.status, subject: this.subject, b
ユニットテストって何?って人向けのmochaとchaiの使い方 を見ていて、 MochaとChaiの事が気になったので、簡単な使いかたをメモ。 フォルダ構成 (Nodeが動く環境用) / L package.json L /test package.json (抜粋) "scripts": { "test": "mocha" }, テスト用のコードは、/test 直下に置きます。 (mochaの自動検索対象は、/test直下のみ。) Visual Studio Codeにnpm用の拡張機能を入れておくと、 Ctrl+R Tでテストが実行できるので便利! (npm run-script test testが呼ばれます。) 参照: Mocha: Getting Started 以上! ・・で終わってもよいのですが、以下おまけ。 Chaiの使いどころ:assert以外のものも使える Mochaに
はじめに 流行りの redux を React 等、他のフレームワーク/ライブラリと【組み合わせず】に触ってみたので、その記録を残します。 redux という言葉を最近よく聞くけど何なのかは知らない人に、redux がどういうものなのかを知って、使い始めてもらえればもらえれば幸いです。 ついでに、redux はユニットテストに落とし込みやすいと知ったので、mochaとchaiを使ってユニットテストも書いています。 良ければご参考に。 対象 この記事は redux を触ったことがない JS はある程度触ったことがある (必須)webpack, ES6記法 を多分に使っているので、読むことが出来る方 を対象としています。 Redux とは こちらの記事が素晴らしくわかりやすい概念の説明(なんならこれだけでもだいたい理解できちゃう…)が載っているのでぜひご覧ください。 reduxは一言でいうと、
chai.use(chaiHttp); const binaryParser = (res, cb) => { res.setEncoding("binary"); res.data = ""; res.on("data", function (chunk) { res.data += chunk; }); res.on("end", function () { cb(null, new Buffer(res.data, "binary")); }); }; describe('test', function(){ it('API request test', (done) => { chai.request('http://www.example.com') .post('/api/hogehoge') .set('Content-Type', 'application/x-www-fo
ちょっとした仕事で、ちゃんとした、 JavaScript のテストコードを書く必要性が生じた。動くテストはかけるが、あまり慣れていない言語で「適切な」テストコードがかけているかは正直わからない。まとまったラーニングコースを受けてみるつもりだが、2ビジネス営業日かかるみたいなので、まず最初に作ってみた。 テストフレームワークをどれを使うかはあたりがついている。Mochaとchai。これは、TypeScriptの頃から同じなので、馴染みがある。そもそもBDD形式のフレームワークなので、使い方はどれも似ている。 Mocha は BDDのテストフレームワークで、chai は, expect などのアサーション部分をBDDフレームワークの形式で書けるようになっている。インストールは次の通り
// DB操作を伴うとかそういう系のイメージ const Observable = require("rxjs/Rx").Observable; const { map, finalize, catchError } = require("rxjs/operators"); function foo (val) { console.log("foo!"); return val; } // connection closeは常にしたいとか function teardown () { console.log("teardown!"); } // エラーが起きたときだけrollbackしたいだとか function whenError(err) { console.log("some process..."); throw err; } function wantToDo () { retu
4.0 has been a huge undertaking by the chai community! A lot has changed to ensure Chai 4 is a stable, reliable, well documented codebase. Here are just some of the major improvements: almost all documentation has been rewritten, with detailed instructions on how assertions work, which flags they can be combined with and the best practices for how to use them. deep equality has been rewritten from
この記事の内容 ①テストとは、②mochaとchaiを使ったNode.jsテスト ソフトウェアテスト コンピュータのソフトウェアプログラムを実行し、それが意図したとおりに動くかを観測・評価・検証する作業のこと。通常は検証対象のソフトウェアを実際に試行する動的テストを指すが、レビューなどを静的テストと呼んで広義のテストに含める見方もある。 引用元 http://www.itmedia.co.jp/im/articles/1111/07/news192.html テストケースとは ソフトウェア開発におけるテストは一般に、ユーザーの使用状況を反映した入力データを用いてソフトウェアを実行し、事前に想定した結果と実際の実行結果をつき合わせて合否の判定を行う。このテスト用の“入力データ”とそれを実行したら得られるであろう“事前に想定した結果”の対をテストケースという。すなわち、テストケースを使って対象
Chai Immutable This plugin provides a set of Chai assertions for Facebook’s Immutable library for JavaScript collections. Assertions BDD API Reference (Expect / Should) .empty .equal(collection) .referenceEqual(value) .include(value) .keys(key1[, key2[, ...]]) .property(path[, val]) .size(value) TDD API Reference (Assert) .equal(actual, expected) .referenceEqual(actual, expected) .notEqual(actual,
chai-webdriver Provides selenium-webdriver sugar for the Chai assertion library. Allows you to create expressive integration tests: expect('.frequency-field').dom.to.contain.text('One time') expect('.toggle-pane').dom.to.not.be.visible() What sorts of assertions can we make? All assertions start with a Sizzle-compatible css selector, for example: expect('.list') expect('div > h1') expect('a[href=h
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く