P: ¿Cómo puedo esperar a que terminen todos mis módulos dinámicos antes de mis afirmaciones en Jest?
Guión:
// normal code export default { a() { import('b', () => { window.hello = 'there' }) } } // test import normalCode from 'normalCode' it('should add to window', () => { normalCode.a() expect(window.hello).toBe('there') })La ejecución del código anterior es:
normalCode.a()expect(window.hello).toBe('there')window.hello = 'there'Creo que querrá devolver la promesa de import de la función a .
// normal code export default { a() { return import('b', () => { window.hello = 'there' }) } } Entonces await en tu prueba.
// test import normalCode from 'normalCode' it('should add to window', async () => { await normalCode.a() expect(window.hello).toBe('there') })