|
1 | 1 | import {emit, on} from '@spearwolf/eventize'; |
2 | | -import {createSignal, type Signal, type SignalReader, value} from '@spearwolf/signalize'; |
| 2 | +import {createSignal, value, type Signal, type SignalReader} from '@spearwolf/signalize'; |
3 | 3 | import {afterEach, describe, expect, it, vi} from 'vitest'; |
4 | 4 | import {MessageToView} from '../constants.js'; |
5 | 5 | import type {ShadowObjectCreationAPI} from '../types.js'; |
@@ -1048,4 +1048,33 @@ describe('Kernel', () => { |
1048 | 1048 | kernel.destroy(); |
1049 | 1049 | }); |
1050 | 1050 | }); |
| 1051 | + |
| 1052 | + describe('Entity destruction', () => { |
| 1053 | + it('Entity destruction should destroy children', () => { |
| 1054 | + const registry = new Registry(); |
| 1055 | + const kernel = new Kernel(registry); |
| 1056 | + |
| 1057 | + const destroyCallback = vi.fn(); |
| 1058 | + |
| 1059 | + @ShadowObject({registry, token: 'testOnDestroy'}) |
| 1060 | + class TestOnDestroy { |
| 1061 | + constructor({onDestroy, entity}: ShadowObjectCreationAPI) { |
| 1062 | + onDestroy(() => destroyCallback(entity.uuid)); |
| 1063 | + } |
| 1064 | + } |
| 1065 | + expect(TestOnDestroy).toBeDefined(); |
| 1066 | + |
| 1067 | + const [parentUuid, childUuid] = [generateUUID(), generateUUID()]; |
| 1068 | + |
| 1069 | + kernel.createEntity(parentUuid, 'testOnDestroy'); |
| 1070 | + kernel.createEntity(childUuid, 'testOnDestroy', parentUuid, 0, undefined, true); |
| 1071 | + |
| 1072 | + expect(destroyCallback).not.toHaveBeenCalled(); |
| 1073 | + |
| 1074 | + kernel.destroyEntity(parentUuid); |
| 1075 | + |
| 1076 | + expect(destroyCallback).toHaveBeenNthCalledWith(1, childUuid); |
| 1077 | + expect(destroyCallback).toHaveBeenNthCalledWith(2, parentUuid); |
| 1078 | + }); |
| 1079 | + }); |
1051 | 1080 | }); |
0 commit comments