Commit fa8f884b authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Test boot's browser-extension-utils

parent 97686411
/**
* Tries to get the extension ID which is running this script, or undefined if
* this script is not being run by the browser extension
* Returns the extension ID which is running this script, or undefined if this
* script is not being run by the browser extension.
*
* @param {Window} window_
* @return {string | undefined}
......@@ -11,7 +11,7 @@ export function getExtensionId(window_ = window) {
/**
* Verifies if there's a config script in the document that was generated by a
* specific extension
* specific browser extension.
*
* @param {string} extensionId
* @param {Document} document_
......
import { getExtensionId, hasExtensionConfig } from '../browser-extension-utils';
describe('browser-extension-utils', () => {
describe('getExtensionId', () => {
[
{ window: {}, expectedId: undefined },
{
window: {
chrome: {},
},
expectedId: undefined,
},
{
window: {
chrome: {
runtime: {},
},
},
expectedId: undefined,
},
{
window: {
chrome: {
runtime: { id: 'hypothesisId' },
},
},
expectedId: 'hypothesisId',
},
].forEach(({ window, expectedId }) => {
it('returns the extension ID only when running in the scope of a browser extension', () => {
assert.equal(getExtensionId(window), expectedId);
});
});
});
describe('hasExtensionConfig', () => {
let fakeDocument;
beforeEach(() => {
fakeDocument = {
querySelector: sinon.stub(),
};
});
[
{ element: null, configExists: false },
{ element: {}, configExists: true },
].forEach(({ element, configExists }) => {
it('returns proper result if the config script was found', () => {
fakeDocument.querySelector.returns(element);
assert.equal(
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