Make sure graph vertex value is converted to string

This commit is contained in:
Alex Rock Ancelet
2019-12-18 08:45:00 +01:00
committed by Oleksii Trekhleb
parent 53f8c0dc24
commit 0d956c2253
2 changed files with 17 additions and 1 deletions

View File

@@ -133,6 +133,6 @@ export default class GraphVertex {
* @returns {string}
*/
toString(callback) {
return callback ? callback(this.value) : `${this.value}`;
return callback ? callback(this.value).toString() : this.value.toString();
}
}

View File

@@ -185,4 +185,20 @@ describe('GraphVertex', () => {
expect(vertexA.getEdges().length).toEqual(3);
});
it('should execute callback when passed to toString', () => {
const vertex = new GraphVertex('A');
expect(vertex.toString(() => 'B')).toEqual('B');
});
it('should execute toString on value when calling toString on vertex', () => {
const value = {
toString() { return 'A'; },
};
const vertex = new GraphVertex(value);
expect(vertex.toString()).toEqual('A');
});
});