1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
3 * jQuery test with DOM/windows object
8 var fs = require("fs");
9 var utils = require("./mkws_utils.js");
12 * parse HTML data to DOM, and run jQuery request on it
16 function jsdom_check (file, tags_array, ignore_doctype) {
17 var html = fs.readFileSync(file, "utf-8");
18 var tags = utils.flat_list(tags_array);
20 describe("index-full.html jsdom + jquery for " + file, function() {
21 var window = require('jsdom').jsdom(html, null, {
22 FetchExternalResources: false,
23 ProcessExternalResources: false,
24 MutationEvents: false,
28 /* apply jquery to the window */
29 var $ = require('jquery').create(window);
32 it("html jquery test", function() {
33 expect(html).toBeDefined();
35 expect($("body").length == 0).toEqual(false);
36 expect($("body").length == 1).toEqual(true);
37 expect($("head").length == 1).toEqual(true);
39 for(var i = 0; i < tags.length; i++) {
40 expect($("#" + tags[i]).length == 1).toEqual(true);
44 it("html jquery fail test", function() {
45 expect(html).toBeDefined();
47 expect($("body_does_not_exists").length == 1).toEqual(false);
48 expect($("#body_does_not_exists").length == 1).toEqual(false);
53 jsdom_check('../examples/htdocs/index-full.html', [utils.tags.required, utils.tags.optional, utils.tags.optional2]);
54 jsdom_check('../examples/htdocs/index-mobile.html', [utils.tags.required, utils.tags.optional]);
55 jsdom_check('../examples/htdocs/index-popup.html', [], true);
56 jsdom_check('../examples/htdocs/index-jquery.html', []);
57 jsdom_check('../examples/htdocs/index-mike.html', [utils.tags.required, utils.tags.optional], true);