From a4ea36399f123959f7505e9b7ad14d65670bc565 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 15 Sep 2023 12:34:54 +0200 Subject: [PATCH] MOBILE-4420 behat: Support sync network requests --- src/testing/services/behat-blocking.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/testing/services/behat-blocking.ts b/src/testing/services/behat-blocking.ts index 68498ed3a..8ae1d02be 100644 --- a/src/testing/services/behat-blocking.ts +++ b/src/testing/services/behat-blocking.ts @@ -236,15 +236,27 @@ export class TestingBehatBlockingService { NgZone.run(() => { const index = requestIndex++; const key = 'httprequest-' + index; + const isAsync = args[2] !== false; try { - // Add to the list of pending requests. + // Add to the list of pending requests. TestingBehatBlocking.block(key); // Detect when it finishes and remove it from the list. - this.addEventListener('loadend', () => { - TestingBehatBlocking.unblock(key); - }); + if (isAsync) { + this.addEventListener('loadend', () => { + TestingBehatBlocking.unblock(key); + }); + } else { + const realSend = this.send; + this.send = (...args) => { + try { + return realSend.apply(this, args); + } finally { + TestingBehatBlocking.unblock(key); + } + }; + } return realOpen.apply(this, args); } catch (error) {