Skip to content

Commit

Permalink
feat(playground): emit formPlayground.inputDataError
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Kiefer committed Nov 4, 2022
1 parent bacd09b commit 7aeca3f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/form-js-playground/src/components/PlaygroundRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ export function PlaygroundRoot(props) {
});

dataEditor.on('changed', event => {

try {
setData(JSON.parse(event.value));
} catch (err) {
} catch (error) {

// TODO(nikku): indicate JSON parse error
// notify interested about input data error
emit('formPlayground.inputDataError', error);
}
});

Expand Down
26 changes: 26 additions & 0 deletions packages/form-js-playground/test/spec/Playground.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,32 @@ describe('playground', function() {
expect(spy).to.have.been.called;
});


it('should emit <formPlayground.inputDataError>', async function() {

// given
await act(() => {
playground = new Playground({
container,
schema
});
});

let trackedError;

playground.on('formPlayground.inputDataError', e => trackedError = e);

// when
await act(() => {
const dataEditor = playground.getDataEditor();
dataEditor.emit('changed', { value: 'foo' });
});

// then
expect(trackedError).to.exist;
expect(trackedError.toString()).to.eql('SyntaxError: Unexpected token o in JSON at position 1');
});

});


Expand Down

0 comments on commit 7aeca3f

Please sign in to comment.