Skip to content

Commit 87b67d5

Browse files
Add test for error handling in NotebookPicker constructor
Improves test coverage for the .catch() error handler added to handle promise rejections in the constructor.
1 parent 18782e5 commit 87b67d5

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/__tests__/NotebookPicker.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,35 @@ describe('NotebookPicker', () => {
108108
expect(select.options.length).toBeGreaterThanOrEqual(1);
109109
expect(select.options[0] && select.options[0].value).toBe('-');
110110
});
111+
112+
it('should handle context.ready rejection gracefully', async () => {
113+
const consoleErrorSpy = jest
114+
.spyOn(console, 'error')
115+
.mockImplementation(() => {});
116+
const errorPanel = {
117+
context: {
118+
ready: Promise.reject(new Error('Failed to initialize')),
119+
model: {
120+
getMetadata: jest.fn()
121+
}
122+
},
123+
model
124+
} as any;
125+
126+
document.body.innerHTML = '';
127+
const widget = new NotebookPicker(errorPanel);
128+
// Override onAfterAttach to avoid errors from this.parent being null
129+
(widget as any).onAfterAttach = jest.fn();
130+
Widget.attach(widget, document.body);
131+
await framePromise();
132+
133+
await new Promise(resolve => setTimeout(resolve, 10));
134+
135+
expect(consoleErrorSpy).toHaveBeenCalledWith(
136+
'Failed to initialize NotebookPicker:',
137+
expect.any(Error)
138+
);
139+
140+
consoleErrorSpy.mockRestore();
141+
});
111142
});

0 commit comments

Comments
 (0)