Added test suggested on PR

This commit is contained in:
RounakJoshi09 2023-10-10 11:09:30 +05:30
parent cdb4639aa4
commit ce3d9fcdde
2 changed files with 18 additions and 2 deletions

View File

@ -194,7 +194,7 @@ export const updateLink = function (positions, style) {
positions.forEach(function (pos) {
if (pos >= edges.length) {
let error = new Error(
`Incorrect index ${pos} of linkStyle. (Help: Index must be from 0 to ${edges.length - 1})`
`The index for linkStyle is out of bounds. (Help: Ensure that the index is within the range of existing edges.)`
);
throw error;
}

View File

@ -287,7 +287,23 @@ describe('[Style] when parsing', () => {
});
it('should handle style definitions within number of edges', function () {
const res = flow.parser.parse('graph TD\n' + 'A-->B\n' + 'linkStyle 0 stroke-width:1px;');
try {
flow.parser.parse(`graph TD
A-->B
linkStyle 1 stroke-width:1px;`);
// Fail test if above expression doesn't throw anything.
expect(true).toBe(false);
} catch (e) {
expect(e.message).toBe(
`The index for linkStyle is out of bounds. (Help: Ensure that the index is within the range of existing edges.)`
);
}
});
it('should handle style definitions within number of edges', function () {
const res = flow.parser.parse(`graph TD
A-->B
linkStyle 0 stroke-width:1px;`);
const edges = flow.parser.yy.getEdges();