Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/modules/saver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default class Saver extends Module {
return this.makeOutput(sanitizedData);
} catch (e) {
_.logLabeled(`Saving failed due to the Error %o`, 'error', e);

throw e;
}
}

Expand Down
80 changes: 80 additions & 0 deletions test/cypress/tests/modules/Saver.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,88 @@
import type EditorJS from '../../../../types/index';
import Header from '@editorjs/header';
import ToolMock from '../../fixtures/tools/ToolMock';

describe('Saver module', function () {
describe('save()', function () {
['throws', 'rejects'].forEach((failureMode) => {
it(`should reject with the original error when a tool's save() ${failureMode}`, function () {
const saveError = new Error('Tool failed to save');
const save = cy.stub(ToolMock.prototype, 'save');

if (failureMode === 'throws') {
save.throws(saveError);
} else {
save.rejects(saveError);
}

cy.createEditor({
tools: {
failingTool: ToolMock,
},
data: {
blocks: [
{
type: 'failingTool',
data: { text: 'Unsaved content' },
},
],
},
}).then((editor: EditorJS) => {
return editor.save().then(
(data) => {
assert.fail(`Expected save() to reject, but it resolved with ${JSON.stringify(data)}`);
},
(error) => {
expect(error).to.equal(saveError);
}
);
});
});
});

it('should skip invalid blocks and save valid blocks', function () {
cy.createEditor({
data: {
blocks: [
{
type: 'paragraph',
data: { text: '' },
},
{
id: 'valid-block',
type: 'paragraph',
data: { text: 'Valid content' },
},
],
},
}).then(async (editor: EditorJS) => {
const data = await editor.save();

expect(data.blocks).to.deep.equal([
{
id: 'valid-block',
type: 'paragraph',
data: { text: 'Valid content' },
},
]);
});
});

it('should still reject saving in read-only mode', function () {
cy.createEditor({
readOnly: true,
}).then((editor: EditorJS) => {
return editor.save().then(
() => {
assert.fail('Expected saving in read-only mode to reject');
},
(error) => {
expect(error.message).to.equal('Editor\'s content can not be saved in read-only mode');
}
);
});
});

it('should correctly save block if there are some 3rd party (eg. browser extensions) nodes inserted into the layout', function () {
cy.createEditor({
data: {
Expand Down
Loading