Skip to content

Commit 2c7c137

Browse files
authored
Merge pull request #94 from WebSpellChecker/handle-wrong-bundle-loading
Handle wrong bundle loading
2 parents 1af1208 + a2c7d0a commit 2c7c137

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/wproofreader.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ export default class WProofreader extends Plugin {
150150
_loadWscbundle() {
151151
const scriptLoader = new ScriptLoader(this._userOptions.srcUrl);
152152

153-
return scriptLoader.load();
153+
return scriptLoader.load()
154+
.then(() => {
155+
if (!window.WEBSPELLCHECKER) {
156+
throw new Error('WEBSPELLCHECKER is not defined.');
157+
}
158+
});
154159
}
155160

156161
/**
@@ -278,7 +283,7 @@ export default class WProofreader extends Plugin {
278283
* @private
279284
*/
280285
_createInstance(root) {
281-
WEBSPELLCHECKER.init(this._mergeOptions(root), this._handleInstanceCreated.bind(this));
286+
window.WEBSPELLCHECKER.init(this._mergeOptions(root), this._handleInstanceCreated.bind(this));
282287
}
283288

284289
/**

tests/mocks/mock-script.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(function() { })()

tests/wproofreader.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,26 @@ describe('WProofreader', () => {
452452
expect(editor.editing.view.getDomRoot('main')).to.not.be.equal(span);
453453
});
454454
});
455+
456+
describe('_loadWscbundle() method', () => {
457+
it('should throw an error if WEBSPELLCHECKER is not defined', () => {
458+
const options = { srcUrl: 'http://localhost:3000/tests/mocks/mock-script.js' };
459+
const copy = window.WEBSPELLCHECKER;
460+
461+
delete window.WEBSPELLCHECKER;
462+
463+
const wproofreader = new WProofreader();
464+
wproofreader._userOptions = options;
465+
466+
return wproofreader._loadWscbundle()
467+
.catch((e) => {
468+
expect(e.message).to.be.equal('WEBSPELLCHECKER is not defined.');
469+
})
470+
.finally(() => {
471+
window.WEBSPELLCHECKER = copy;
472+
});
473+
});
474+
});
455475
});
456476

457477
describe('in CKEditor 5 restricted editing mode', () => {

0 commit comments

Comments
 (0)