javascriptのユニットテストにPhantomjsとJasmineを使用したいと思います。PhantomjsのWebサイトでは、これを処理するために別のもの、具体的にはPhantomJasmineを使用することを推奨しています。PhantomJasmineをダウンロードして、例を実行しました。すべてが完璧に進みました。var system = require('system');
次に、example_spec.jsの先頭に行を追加しました。「ReferenceError:Ca n't find variable:require」という例を実行しようとすると、Phantomjsがエラーをスローするようになりました。したがって、ブラウザを起動するなどの必要がありますが、jasmineとphantomjsの構文を組み合わせることができないようです。Phantomjsを使用してのみ純粋なジャスミンを実行できます。同じファイルで両方を使用するにはどうすればよいですか?お気に入り:
console.log('Loading a web page');
var page = new WebPage();
var url = "http://www.phantomjs.org/";
page.open(url, function (status) {
//Page is loaded!
describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
});
phantom.exit();
});