12月 2012年

jasmineを用いたBDD (2) 正常系

strong { display: inline-block; margin: 1.2em 0; } ※jasmineの公式サイトはこちら。 Spec記述の基本 実際に Spec(テストコード) を書いていきます。 今回はもっとも一般的(?)な正常系の記述をすることで、テストコードの書き方を試してみます。 describe('"g.date.W3CDTF.parse" public static method', function () { it('"YYYY-MM-DDThh:mmTZD"フォーマット文字列からDateオブジェクトへ変換できる ', function () { expect( new Date(1997, 6, 16, 19, 20, 0) ).toEqual( ...

"!~" と "<0" どちらが速い?

文字列中に指定した文字列が含まれているかどうかを調べるのに"indexOf"を使う。 この indexOf の評価方法で、「指定した文字列が含まれない」ことを調べるのに "<0"を用いた方法ではなく、チルダ(~)を使った方法があるらしい。 "<0" を使った記述 var text = 'As flies to wanton boys are we to the gods, they kill us for their sport.'; if (text.indexOf('gods') < 0) { // 'gods' が含まれない場合 } else { // 'gods' が含まれる場合 } "!~" を使った記述 var text = 'As flies to wanton boys are we to the gods, they kill us for ...