Skip to content

Commit fe9a38b

Browse files
author
Oleksandr Dzhychko
committed
test(vue-model-api): add test to show garbage collection breaking reactivity
Relates to: MODELIX-1041
1 parent 5720ecf commit fe9a38b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

vue-model-api/src/internal/ReactiveINodeJS.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useModelsFromJson } from "../useModelsFromJson";
22
import { computed, isReactive, reactive } from "vue";
3+
import { runGarbageCollection } from "./runGarbageCollection";
34

45
const root = {
56
root: {
@@ -159,3 +160,22 @@ test("removing a node is reactive", () => {
159160
node.remove();
160161
expect(computedProperty.value).toHaveLength(childCount - 1);
161162
});
163+
164+
test("garbage collection does not break reactivity", async () => {
165+
const rootNode = useRootNode();
166+
// Do not assign the child object to a variable because this would prevent GC from collecting.
167+
// MODELIX-1041 was caused by child object being garbage collected even when Vue components were subscribed to their properties.
168+
function getChild() {
169+
return rootNode.getAllChildren()[0];
170+
}
171+
getChild().setPropertyValue("name", "firstName");
172+
const computedChildNames = computed(() =>
173+
getChild().getPropertyValue("name"),
174+
);
175+
expect(computedChildNames.value).toEqual("firstName");
176+
177+
await runGarbageCollection();
178+
getChild().setPropertyValue("name", "secondName");
179+
180+
expect(computedChildNames.value).toEqual("secondName");
181+
});

0 commit comments

Comments
 (0)