Egg-Mock Getting can't get httpRequest before ready while running unit test

53 Views Asked by At

I am getting error while running test cases, below are the dependencies I am using, Can you please let me know what I am doing wrong here ?

"egg-mock": "^3.20.0",    
"jest": "^26.4.0",
"egg": "^3.3.3",
"@midwayjs/core": "^3.0.0",

Below is the sample code snippet I am using in my test file:

import mock from 'egg-mock';

describe('some test', () => {
  let app;
  beforeEach(async () => {
    app = mock.app();
    await app.ready();
  })
  afterEach(() => app.close());

  it('should request /api/test', () => {
    const result = app.httpRequest()
      .get('/api/test');

    expect(result.status).toBe(200);
  });
});

Below is the error I am getting while running the test case (yarn run test):

some test › should request /api/test

    assert(received)

    Expected value to be equal to:
      true
    Received:
      false

      at fixWinEPERM (node_modules/mz-modules/node_modules/rimraf/rimraf.js:175:5)
      at node_modules/mz-modules/node_modules/rimraf/rimraf.js:149:7

  ● some test › should request /api/test

    can't get httpRequest before ready

      10 |
      11 |   it('should request /api/test', () => {
    > 12 |     const result = app.httpRequest()
         |                        ^
      13 |       .get('/api/test');
      14 |
      15 |     expect(result.status).toBe(200);

      at Object.get (node_modules/egg-mock/lib/app.js:197:36)
0

There are 0 best solutions below