-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.js
44 lines (35 loc) · 1.1 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
const {JSDOM} = require('jsdom');
const it = require('tape');
const gitHubInjection = require('./');
const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
global.document = dom.window.document;
global.Event = dom.window.Event;
it('throws an error if callback function is missing', assert => {
assert.throws(() => gitHubInjection(), /Missing argument callback/);
assert.end();
});
it('throws an error if called without a callback function', assert => {
assert.throws(() => gitHubInjection({}), /Callback is not a function/);
assert.end();
});
it('accepts a callback function', assert => {
assert.doesNotThrow(() => gitHubInjection(() => {}));
assert.end();
});
it('calls callback function on initializtion', assert => {
let count = 0;
assert.doesNotThrow(() => gitHubInjection(() => count++));
assert.equal(count, 1);
assert.end();
});
it('calls callback function when pjax:end event was dispatched', assert => {
assert.plan(1);
let count = 0;
gitHubInjection(() => {
count++;
if (count === 2) {
assert.pass();
}
});
document.dispatchEvent(new Event('pjax:end'));
});