4831: Tests pass with "make test", "mocha --watch", and browser at /test.html
[arvados.git] / apps / backstage / test / mithril-dom.js
1 var $ = require('jquery')
2 , jsdom = require('jsdom')
3 , m = require('mithril');
4
5 module.exports = md;
6
7 var global = (function() { return this })();
8 var jsdomWin = global;
9
10 md.ready = function(cb) {
11     if (typeof window !== 'undefined' && global === window) {
12         cb($);
13         return;
14     }
15     jsdom.env({
16         html: '<html></html>',
17         scripts: [
18             '../node_modules/jquery/dist/jquery.js',
19             '../node_modules/mithril/mithril.js',
20         ],
21         done: function(err, win) {
22             jsdomWin = win;
23             $ = win.jQuery;
24             cb($);
25         }
26     });
27 }
28
29 function md(cell) {
30     var div = $('<div></div>')[0];
31     (jsdomWin.m || m).render(div, cell);
32     return div.children;
33 }