Skip to content

Commit 21474b0

Browse files
dsmmckenclaude
andcommitted
fix: improve golden-layout test cleanup and fix replaceChild bug
- Make cleanupLayout() assert on destruction instead of swallowing errors - Fix replaceChild event subscription bug by adding Tab.setContentItem() that properly transfers event listeners when content item changes - Remove redundant explicit "destroys the layout" tests (afterEach now validates destruction after every test) - Add migration plan documentation Test count: 91 total (89 passing, 2 skipped popout tests) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ceb7a98 commit 21474b0

19 files changed

Lines changed: 647 additions & 329 deletions

packages/golden-layout/plans/karma-to-jest-migration-plan.md

Lines changed: 518 additions & 0 deletions
Large diffs are not rendered by default.

packages/golden-layout/src/__tests__/component-creation-events.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,4 @@ describe('emits events when components are created', () => {
8787
expect(eventListener.show).toHaveBeenCalledTimes(1);
8888
expect(eventListener.shown).toHaveBeenCalledTimes(1);
8989
});
90-
91-
it('destroys the layout', async () => {
92-
layout = createTestLayout(
93-
{
94-
content: [
95-
{
96-
type: 'component',
97-
componentName: 'testComponent',
98-
},
99-
],
100-
},
101-
class {
102-
constructor(cont: ItemContainer) {
103-
cont.getElement().html('that worked');
104-
}
105-
}
106-
);
107-
108-
layout.init();
109-
await waitForLayoutInit(layout);
110-
111-
layout.destroy();
112-
expect(layout.root.contentItems.length).toBe(0);
113-
});
11490
});

packages/golden-layout/src/__tests__/component-state-save.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,4 @@ describe("Sets and retrieves a component's state", () => {
120120

121121
expect(getComponentState(myLayout).testValue).toBe('updated');
122122
});
123-
124-
it('Destroys the layout', async () => {
125-
myLayout = createTestLayout(
126-
statefulConfig,
127-
class {
128-
constructor(cont: ItemContainer) {
129-
cont.getElement().html('that worked');
130-
}
131-
}
132-
);
133-
await initLayout(myLayout);
134-
135-
myLayout.destroy();
136-
expect(myLayout.root.contentItems.length).toBe(0);
137-
});
138123
});

packages/golden-layout/src/__tests__/deferred-create-drag.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,4 @@ describe('supports drag creation with deferred content', () => {
229229
restoreMocks();
230230
}
231231
});
232-
233-
it('destroys the layout', async () => {
234-
layout = await createLayout({
235-
content: [
236-
{
237-
type: 'component',
238-
componentName: 'testComponent',
239-
},
240-
],
241-
});
242-
243-
layout.destroy();
244-
expect(layout.root.contentItems.length).toBe(0);
245-
});
246232
});

packages/golden-layout/src/__tests__/disabled-selection.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,4 @@ describe('selection is disabled by default', () => {
132132
expect(selectionChangedSpy).toHaveBeenCalledTimes(0);
133133
expect(layout.selectedItem).toBe(null);
134134
});
135-
136-
it('destroys the layout', async () => {
137-
layout = await createLayout({
138-
content: [
139-
{
140-
type: 'component',
141-
componentName: 'testComponent',
142-
},
143-
],
144-
});
145-
146-
layout.destroy();
147-
expect(layout.root.contentItems.length).toBe(0);
148-
});
149135
});

packages/golden-layout/src/__tests__/drag.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,4 @@ describe('supports drag creation', () => {
229229
restoreMocks();
230230
}
231231
});
232-
233-
it('destroys the layout', async () => {
234-
layout = await createLayout({
235-
content: [
236-
{
237-
type: 'component',
238-
componentName: 'testComponent',
239-
},
240-
],
241-
});
242-
243-
layout.destroy();
244-
expect(layout.root.contentItems.length).toBe(0);
245-
});
246232
});

packages/golden-layout/src/__tests__/empty-item.test.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,4 @@ describe('The layout can handle empty stacks', () => {
110110

111111
expect(stack.contentItems.length).toBe(1);
112112
});
113-
114-
it('destroys the layout', async () => {
115-
myLayout = await createLayout({
116-
content: [
117-
{
118-
type: 'row',
119-
content: [
120-
{
121-
type: 'component',
122-
componentName: 'testComponent',
123-
},
124-
{
125-
isClosable: false,
126-
type: 'stack',
127-
content: [],
128-
},
129-
],
130-
},
131-
],
132-
});
133-
134-
myLayout.destroy();
135-
expect(myLayout.root.contentItems.length).toBe(0);
136-
});
137113
});

packages/golden-layout/src/__tests__/enabled-selection.test.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -258,21 +258,4 @@ describe('selection works when enabled', () => {
258258
expect(stackA.element.hasClass('lm_selected')).toBe(true);
259259
expect(stackB.element.hasClass('lm_selected')).toBe(false);
260260
});
261-
262-
it('destroys the layout', async () => {
263-
layout = await createLayout({
264-
settings: {
265-
selectionEnabled: true,
266-
},
267-
content: [
268-
{
269-
type: 'component',
270-
componentName: 'testComponent',
271-
},
272-
],
273-
});
274-
275-
layout.destroy();
276-
expect(layout.root.contentItems.length).toBe(0);
277-
});
278261
});

packages/golden-layout/src/__tests__/event-bubble.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,18 +194,4 @@ describe('content items are abled to to emit events that bubble up the tree', ()
194194
expect(invocations[1]).toBe('stackBottom');
195195
expect(invocations[2]).toBe('column');
196196
});
197-
198-
it('destroys the layout', async () => {
199-
layout = await createLayout({
200-
content: [
201-
{
202-
type: 'component',
203-
componentName: 'testComponent',
204-
},
205-
],
206-
});
207-
208-
layout.destroy();
209-
expect(layout.root.contentItems.length).toBe(0);
210-
});
211197
});

packages/golden-layout/src/__tests__/id.test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,4 @@ describe('Dynamic ids work properly', () => {
139139
item.removeId('non_existent_id');
140140
}).toThrow();
141141
});
142-
143-
it('destroys the layout', async () => {
144-
layout = await createLayout({
145-
content: [
146-
{
147-
type: 'component',
148-
componentName: 'testComponent',
149-
},
150-
],
151-
});
152-
153-
layout.destroy();
154-
expect(layout.root.contentItems.length).toBe(0);
155-
});
156142
});

0 commit comments

Comments
 (0)