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
parent 37f3d54aff
commit 9465d0e4c4
No known key found for this signature in database
GPG Key ID: 4A7B1CB0178A73F5
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');
});
});