Skip to content

Commit 6960519

Browse files
committed
add test case for removing nested refIds
1 parent 400d217 commit 6960519

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/MapSchema.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,39 @@ describe("Type: MapSchema", () => {
323323
assertDeepStrictEqualEncodeAll(state);
324324
});
325325

326+
it("removing item with children should remove children as well", () => {
327+
class Item extends Schema {
328+
@type("string") name: string;
329+
}
330+
class Entity extends Schema {
331+
@type("string") name: string;
332+
@type([Item]) items = new ArraySchema<Item>();
333+
}
334+
class State extends Schema {
335+
@type({map: Entity}) entities = new MapSchema<Entity>();
336+
}
337+
338+
const state = new State();
339+
for (let i = 0; i < 5; i++) {
340+
state.entities.set("e" + i, new Entity().assign({
341+
name: "Entity " + i,
342+
items: [
343+
new Item().assign({ name: "Item A" }),
344+
new Item().assign({ name: "Item B" }),
345+
]
346+
}));
347+
}
348+
349+
const decodedState = createInstanceFromReflection(state);
350+
decodedState.decode(state.encode());
351+
352+
assertRefIdCounts(state, decodedState);
353+
354+
state.entities.delete("e3");
355+
decodedState.decode(state.encode());
356+
assertRefIdCounts(state, decodedState);
357+
});
358+
326359
it("should allow map of primitive types", () => {
327360
class Player extends Schema {
328361
@type({ map: "number" }) mapOfNumbers = new MapSchema<number>();

0 commit comments

Comments
 (0)