test: fix race in reentrant loadURL() ready-to-commit test (#51315)

test: fix race in reentrant loadURL() ready-to-commit test

Fix 'fails if loadurl is called after the navigation is ready to commit'
by using a done() callback to ensure the test waits for did-fail-load
before exiting.

Previously, the test would return and call afterEach(closeAllWindows),
potentially destroying the window while navigation was in flight.
This commit is contained in:
Charles Kerr
2026-04-26 09:40:04 -05:00
committed by GitHub
parent 5af1a06082
commit ded39eecc7

View File

@@ -558,9 +558,10 @@ describe('webContents module', () => {
w.loadURL('data:text/html,<h1>HELLO</h1>');
});
it('fails if loadurl is called after the navigation is ready to commit', () => {
it('fails if loadurl is called after the navigation is ready to commit', (done) => {
w.webContents.once('did-fail-load', (_event, _errorCode, _errorDescription, validatedURL) => {
expect(validatedURL).to.contain('blank.html');
done();
});
// @ts-expect-error internal-only event.