Tengo una función como esta:
let settings = { isRun: false } function testPromise(promise) { settings.isRun = true; return promise.finally(() => settings.isRun = false;) }¿Cómo se puede probar isRun = true cuando se ejecuta testPromise antes de ejecutar finalmente la expresión? probé con
it('should isRun true when testPromise running', async () => { expect(settings.isRun).toBeFalsy(); await testPromise(Promise.resolve('run')).then(() => { expect(settings.isRun).toBeTruthy(); } expect(settings.isRun).toBeFalsy();Pero no funciona
Creo que puede ejecutar pero no esperar a que la promesa observe el cambio de valor intermitente que desea ver.
it('should isRun true when testPromise running', () => { expect(settings.isRun).toBeFalsy(); const promise = testPromise(Promise.resolve('run')); // At this point, promise is not resolved yet, so the callback in finally has not executed yet. expect(settings.isRun).toBeTruthy(); // If you want to test it changed back to fasle promise.then(() => { expect(settings.isRun).toBeFalsy(); }); }