-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
68 lines (53 loc) · 1.79 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
describe('htmlfile', function () {
'use strict';
function ActiveXObject(type) {
this.type = type;
this.data = [];
this.body = '';
}
ActiveXObject.prototype.open = function () { return this.data.push('open'); };
ActiveXObject.prototype.close = function () { return this.data.push('close'); };
ActiveXObject.prototype.write = function (data) { this.body += data; };
//
// Really minimum viable ActiveXObject polyfill for a HTMLfiles. This allows
// us to check if everything works as intended.
//
global.ActiveXObject = ActiveXObject;
var calls = 0;
global.CollectGarbage = function () { calls++; };
var assume = require('assume')
, htmlfile = require('./');
it('is exported as a function', function () {
assume(htmlfile).is.a('function');
});
it('opens and closes the htmlfile', function () {
var html = htmlfile();
assume(html.data[0]).equals('open');
assume(html.data[1]).equals('close');
});
it('adds the supplied domain', function () {
var html = htmlfile('foo.com');
assume(html.body).to.include('foo.com');
assume(html.body).to.include('document.domain=');
});
it('only adds the domain if it can find one', function () {
var html = htmlfile();
assume(html.body).does.not.include('foo.com');
assume(html.body).does.not.include('document.domain=');
});
describe('.supported', function () {
it('is a boolean', function () {
assume(htmlfile.supported).is.a('boolean');
});
it('is true, as this is node.js & we polyfilled it', function () {
assume(htmlfile.supported).is.true();
});
});
describe('#destroy', function () {
it('calls the CollectGarbage method', function () {
assume(calls).equals(0);
htmlfile.destroy();
assume(calls).equals(1);
});
});
});