From 83124b3da476d97770993d16ef5a037fdefb6bf1 Mon Sep 17 00:00:00 2001 From: Klemek Date: Mon, 15 Jul 2019 10:59:43 +0200 Subject: [PATCH] type enforcement unit tests --- test/placing.test.js | 20 +++++++++++++++++++- test/rendering.test.js | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/test/placing.test.js b/test/placing.test.js index 1500174..c127641 100644 --- a/test/placing.test.js +++ b/test/placing.test.js @@ -397,9 +397,27 @@ describe('compute', () => { }; test('no nodes', () => { - const nodes = placing({diagonals: false}).compute({}, []); + const nodes = placing().compute({}, []); expect(nodes).toEqual({}); }); + test('invalid node', () => { + try { + placing().compute({ + 'a': {name: 'a', x: 'hello'} + }, []); + fail('no error thrown'); + } catch (err) { + expect(err).toBe('node \'a\' is invalid at key x'); + } + }); + test('invalid link', () => { + try { + placing().compute({}, [{from: 'a', to: 5}]); + fail('no error thrown'); + } catch (err) { + expect(err).toBe('link 0 (a->5) is invalid at key to'); + } + }); test('3 nodes no link', () => { const nodes = placing({diagonals: false}).compute(createNodes(3), []); expect(nodes).toEqual({ diff --git a/test/rendering.test.js b/test/rendering.test.js index ec920ab..828cc25 100644 --- a/test/rendering.test.js +++ b/test/rendering.test.js @@ -124,4 +124,22 @@ describe('compute', () => { const res = rendering({beautify: true, 'h-spacing': 1.2, scale: 20}).compute({}, []); expect(res).toEqual('\n'); }); + test('invalid node', () => { + try { + rendering().compute({ + 'a': {name: 'a', icon: 5} + }, []); + fail('no error thrown'); + } catch (err) { + expect(err).toBe('node \'a\' is invalid at key icon'); + } + }); + test('invalid link', () => { + try { + rendering().compute({}, [{from: 'a', to: 'b', type: 5}]); + fail('no error thrown'); + } catch (err) { + expect(err).toBe('link 0 (a->b) is invalid at key type'); + } + }); }); \ No newline at end of file