Jasmineを使ったテスト
Jasmineを使ったSpecを作っています
SVG 1.1の仕様を補完する形で、Jasmineを使用したSpecをつくっていますが、かなり使えそうです。
BDDという手法では「テスト」という形式ではなくて、あくまでも「Spec」という形をとるようですので、今後はSpec(スペックと称す)として開発していきましょう。もちろん、スペックは開発の一番始めで作るのが基本のようです。しかし、今回はW3Cの仕様が存在しますので、その仕様を補完するつもりで活用していきます。
さっそく、仕様と食い違う点を発見
まずは、以下のようなコードをSvgDomSpec.jsに書いておいて、Jasmineを走らせました。なお、英語は推敲していないので、かなりいい加減です。
describe("SVG Test", function() { var doc, svg; beforeEach(function() { /*前もって実行しておく変数(The 'doc' and 'svg' instances are specified previously.)*/ doc = DOMImplementation.createDocument("http://www.w3.org/2000/svg", "svg"); svg = doc.documentElement; }); describe("SVG Unit :: SVG Length", function() { var s; beforeEach(function() { s = svg.createSVGLength(); }); /*まずは、あるべきデフォルト値かどうかをチェックしていく(Checking the default value of a SVGLength interface.)*/ it("for the default value on the 'value' property", function() { /*See http://www.w3.org/TR/SVG/struct.html#InterfaceSVGDocument * *createSVGLength() * *Creates an SVGLength object outside of any document trees. The object is initialized to the value of 0 user units. *see also http://www.w3.org/TR/SVG/types.html#InterfaceSVGLength * *SVG_LENGTHTYPE_NUMBER (unsigned short) * *No unit type was provided (i.e., a unitless value was specified), which indicates a value in user units. */ expect(s.value).toEqual(0); expect(s.valueInSpecifiedUnits).toEqual(0); expect(s.unitType).toEqual(1); }); }); });
IE8で調べたところ、エラーを発見。そこで、リビジョン2289で修正しておきました。