From e743df6fab242d24dddad13e2d9399b2d642d3c9 Mon Sep 17 00:00:00 2001 From: Alex Rock Ancelet Date: Wed, 18 Dec 2019 08:55:29 +0100 Subject: [PATCH] Make sure toString is called on edge key when calling edge.toString() --- src/data-structures/graph/__test__/GraphEdge.test.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/data-structures/graph/__test__/GraphEdge.test.js b/src/data-structures/graph/__test__/GraphEdge.test.js index c2729845..18dc7317 100644 --- a/src/data-structures/graph/__test__/GraphEdge.test.js +++ b/src/data-structures/graph/__test__/GraphEdge.test.js @@ -51,4 +51,15 @@ describe('GraphEdge', () => { expect(edge.getKey()).toEqual('custom_key'); expect(edge.toString()).toEqual('custom_key'); }); + + it('should execute toString on key when calling toString on edge', () => { + const customKey = { + toString() { return 'custom_key'; }, + }; + + const edge = new GraphEdge(new GraphVertex('A'), new GraphVertex('B'), 0, customKey); + + expect(edge.getKey()).toEqual(customKey); + expect(edge.toString()).toEqual('custom_key'); + }); });