Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flaky Tests with Moxios #75

Open
cashmann opened this issue Mar 3, 2020 · 0 comments
Open

Flaky Tests with Moxios #75

cashmann opened this issue Mar 3, 2020 · 0 comments

Comments

@cashmann
Copy link

cashmann commented Mar 3, 2020

I'm using moxios in two files to mock out API requests and getting tests that seem to randomly fail.
For example:

import { expect } from 'chai'
import moxios from 'moxios'
import { SharedState, updateRenewal, mbcRequest, fetchVersions } from '../../../app/javascript/packs/sharedState.js'

const genericResponse = {
  id: 1,
  status: 'approved',
  versions: ['underwriting', 'approved']
}

describe('SharedState', () => {
  SharedState.currentRenewal = { id: 1 }

  beforeAll(() => {
    moxios.install()
    moxios.stubRequest('/commercial_renewals/1', {
      status: 200,
      response: genericResponse
    })
  })

  afterAll(() => {
    moxios.uninstall()
  })

  describe('updateRenewal', () => {
    let basic_params = {
      id: 1,
      status: 'approved'
    }

    it('updates the attributes on the SharedState updatedRenewals field', (done) => {
      let attribute = basic_params['status'];

      moxios.wait(() => {
        updateRenewal(basic_params);
        expect(SharedState.updatedRenewals[basic_params['id']]['status']).to.equal(attribute);
        done();
      })
    });
  });
...

If I run this test file, followed by another test file with a similar moxios setup, I get various errors around afterAll and variables being undefined and I don't quite get why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant