Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Belio's avatar
Level 18

Async test with AVA and moxios

I am trying to move from mocha to AVA and reproduce this behavior from mocha

it('renders the introduction text if api request is correct', (done) => {
    const vm = mount(AnswerBeat, options);

    moxios.stubRequest('/beatUsers/4', {
      status: 200,
      response: [
        { type: 'text', question: 'example text of question' },
        { type: 'introduction', question: 'INTRODUCTION TEXT HERE' },
      ],
    });

    moxios.wait(() => {
      t.is(vm.welcomeText, 'INTRODUCTION TEXT HERE');
      done();
    });
  });

to AVA. This is my code so far, but test ends with no assertions made:

test('it renders the introduction text if api request is correct', async (t) => {
  const vm = mount(AnswerBeat, options);

  moxios.stubRequest('/beatUsers/4', {
    status: 200,
    response: [
      { type: 'text', question: 'example text of question' },
      { type: 'introduction', question: 'INTRODUCTION TEXT HERE' },
    ],
  });

  await moxios.wait(() => {
    t.is(vm.welcomeText, 'INTRODUCTION TEXT HERE');
  });
});

Thank you!

0 likes
1 reply
Belio's avatar
Belio
OP
Best Answer
Level 18

Here it is:

test.cb('it renders the introduction text if api request is correct', (t) => {
  const vm = mount(AnswerBeat, options);

  moxios.stubRequest('/beatUsers/4', {
    status: 200,
    response: [
      { type: 'text', question: 'example text of question' },
      { type: 'introduction', question: 'INTRODUCTION TEXT HERE' },
    ],
  });

  moxios.wait(() => {
    t.is(vm.welcomeText, 'INTRODUCTION TEXT HERE');
    t.end();
  });
});

Please or to participate in this conversation.