TransWikia.com

how to write mocha test that have timeout and async both

Stack Overflow Asked by Jogiter on December 23, 2021

createStream need to get permission of browser’s video&audio,so i have to delay this test

both createStream and destroyStream return promise

i want to test destroyStream, this just not get what i want, anyone Help?

it("my test need to be delayed, and i want to test destroyStream", function () {
  setTimeout(async () => {
    // i need to create stream first
    const publishStream = await createStream();
    expect(streamCenter.previewVideoList.length).to.equal(1);

    // then destory stream
    await zg.destroyStream(publishStream);
    expect(streamCenter.previewVideoList.length).to.equal(0);
  }, 2000); // my test need to be delayed
});

One Answer

it("my test need to be delayed, and i want to test destroyStream", async function () {
    this.timeout(10000); // set timeout 10s
    // i need to create stream first
    const publishStream = await createStream();
    expect(streamCenter.previewVideoList.length).to.equal(1);

    // then destory stream
    await zg.destroyStream(publishStream);
    expect(streamCenter.previewVideoList.length).to.equal(0);
  
});

this seems work if i allow the permission in time。 otherwise it will failed with Error 'Permission denied'

Answered by Jogiter on December 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP