Commit 6d00836c authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Use real document nodes for browser-extension-utils tests

parent 81469b9f
......@@ -34,29 +34,24 @@ describe('browser-extension-utils', () => {
});
describe('hasExtensionConfig', () => {
let fakeDocument;
beforeEach(() => {
fakeDocument = {
querySelector: sinon.stub(),
};
afterEach(() => {
const script = document.querySelector('.js-hypothesis-config-test');
script?.remove();
});
[
{ element: null, configExists: false },
{ element: {}, configExists: true },
].forEach(({ element, configExists }) => {
[false, true].forEach(configExists => {
it('returns proper result if the config script was found', () => {
fakeDocument.querySelector.returns(element);
if (configExists) {
const configScript = document.createElement('script');
configScript.className =
'js-hypothesis-config js-hypothesis-config-test';
configScript.setAttribute('data-extension-id', 'hypothesisId');
configScript.type = 'application/json';
configScript.innerText = '{}';
document.body.append(configScript);
}
assert.equal(
hasExtensionConfig('hypothesisId', fakeDocument),
configExists
);
assert.calledWith(
fakeDocument.querySelector,
sinon.match('hypothesisId')
);
assert.equal(hasExtensionConfig('hypothesisId'), configExists);
});
});
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment