We override the DraggingTool class to such that our subclass, GuidedDraggingTool, has the following extra method:
canMoveParts() {
return (
this.draggedParts &&
this.draggedParts.first().key.movable !== undefined &&
this.draggedParts.first().key.movable === false
);
}
Part of the requirements involve writing Jasmine unit tests for the above method. e.g.
let sut: GuidedDraggingTool;
...
expect(sut.canMoveParts()).toEqual(false);
To truly test canMoveParts(), I have to set this.draggedParts, which after reading the documentation I understand is supposed to be used as a get-only property:
/**
* Gets the collection of Parts being moved.
* The value is a Map mapping Parts to DraggingInfo Objects
* that have a "point" property remembering the original location of that Part.
*
* #copiedParts provides the map of Parts that have been copied during a copying operation, if any.
*/
draggedParts: Map<Part, DraggingInfo> | null;
Now I tried to mock this.draggedParts like
sut.draggedParts = new Map<go.Part, DraggingInfo>();
then fill up the map; but I got this error:
Type ‘Map<Part, DraggingInfo>’ is missing the following properties from type ‘Map<Part, DraggingInfo>’: add, addAll, first, any, and 14 more.ts(2740)
In addition to help resolve the above error, can you please provide an example of how I would mock a go.Part?
Thanks.