-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.test.js
41 lines (37 loc) · 1.42 KB
/
common.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
import {assert} from 'chai';
import { insertResistButton } from '../src/content/common.js';
import { JSDOM } from "jsdom";
describe('common', function() {
describe('insertResistButton', function() {
it ('properly inserts a button given a button id.', () => {
const dom = new JSDOM(`<!DOCTYPE html><p><button id="buyButtonId">Buy Button </button></p>`);
const docRef = global.document;
global.document = dom.window.document;
global.XPathResult = dom.window.XPathResult;
const res = insertResistButton(
'//*[@id="buyButtonId"]',
'resistButtonId',
'Resist!!'
);
assert.equal(res.innerText, 'Resist!!');
assert.equal(res.id, 'resistButtonId');
assert.isNotNull(dom.window.document.getElementById('resistButtonId'));
global.document = docRef;
global.XPathResult = undefined;
});
it('does not do anything if buyButtonId is not on the page.', () => {
const dom = new JSDOM(`<!DOCTYPE html><p></p>`);
const docRef = global.document;
global.document = dom.window.document;
global.XPathResult = dom.window.XPathResult;
const res = insertResistButton(
'//*[@id="buyButtonIdNotExist"]',
'resistButtonIdNotExist',
'Resist!!'
);
assert.isNull(dom.window.document.getElementById('resistButtonIdNotExist'));
global.document = docRef;
global.XPathResult = undefined;
});
});
})