diff --git a/jest/setup.js b/jest/setup.js index 5fe9ae0..a68d5a4 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -4,7 +4,8 @@ import Adapter from 'enzyme-adapter-react-16'; Enzyme.configure({ adapter: new Adapter() }); Object.defineProperty(document, 'readyState', { - val: 'complete', - get() { return this.val; }, - set(s) { this.val = s; }, + value: 'complete', + writable: true, + enumerable: true, + configurable: true, }); diff --git a/public/index.html b/public/index.html index c203d7c..36bebf6 100644 --- a/public/index.html +++ b/public/index.html @@ -14,7 +14,6 @@ var bookmarklet = "var s= document.createElement('script'); s.setAttribute('src', '"+window.location.href+"bookmarklet.js'); s.setAttribute('crossorigin', 'anonymous'); document.body.appendChild(s);" bookmarklet = '(function(){'+ bookmarklet +'})();' document.querySelector('a#bookmarklet').setAttribute("href", "javascript:" + encodeURIComponent(bookmarklet)); - console.log("DONE"); diff --git a/src/outputs/bookmarklet.js b/src/outputs/bookmarklet.js index 6149977..a183fa6 100644 --- a/src/outputs/bookmarklet.js +++ b/src/outputs/bookmarklet.js @@ -1,10 +1,12 @@ import EmbeddableWidget from './embeddable-widget'; -(function bookmarklet() { +export default function bookmarklet() { if (window.EmbeddableWidget) { return; } window.EmbeddableWidget = EmbeddableWidget; EmbeddableWidget.mount(); -}()); +} + +bookmarklet(); diff --git a/src/outputs/bookmarklet.test.js b/src/outputs/bookmarklet.test.js index 9c3d179..89c8d9b 100644 --- a/src/outputs/bookmarklet.test.js +++ b/src/outputs/bookmarklet.test.js @@ -1,14 +1,17 @@ -import './bookmarklet'; import ReactDOM from 'react-dom'; +import bookmarklet from './bookmarklet'; describe('bookmarklet', () => { afterEach(() => { const el = document.querySelectorAll('body > div'); ReactDOM.unmountComponentAtNode(el[0]); el[0].parentNode.removeChild(el[0]); + window.EmbeddableWidget = null; }); test('#mount document becomes ready', async () => { + expect(window.EmbeddableWidget).not.toBeNull(); + bookmarklet(); const el = document.querySelectorAll('body > div'); expect(el).toHaveLength(1); }); diff --git a/src/outputs/embeddable-widget.test.js b/src/outputs/embeddable-widget.test.js index d2a4db8..6d58519 100644 --- a/src/outputs/embeddable-widget.test.js +++ b/src/outputs/embeddable-widget.test.js @@ -21,7 +21,6 @@ describe('EmbeddableWidget', () => { await waitForSelection(document, 'div'); }); - test('#mount twice', async () => { EmbeddableWidget.mount(); expect(() => EmbeddableWidget.mount()).toThrow('already mounted');