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', () => { ...@@ -34,29 +34,24 @@ describe('browser-extension-utils', () => {
}); });
describe('hasExtensionConfig', () => { describe('hasExtensionConfig', () => {
let fakeDocument; afterEach(() => {
const script = document.querySelector('.js-hypothesis-config-test');
beforeEach(() => { script?.remove();
fakeDocument = {
querySelector: sinon.stub(),
};
}); });
[ [false, true].forEach(configExists => {
{ element: null, configExists: false },
{ element: {}, configExists: true },
].forEach(({ element, configExists }) => {
it('returns proper result if the config script was found', () => { 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( assert.equal(hasExtensionConfig('hypothesisId'), configExists);
hasExtensionConfig('hypothesisId', fakeDocument),
configExists
);
assert.calledWith(
fakeDocument.querySelector,
sinon.match('hypothesisId')
);
}); });
}); });
}); });
......
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