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

TypeError: strapi.stop is not a function #5770

Closed
TheAnimeSenpai opened this issue Apr 11, 2020 · 5 comments
Closed

TypeError: strapi.stop is not a function #5770

TheAnimeSenpai opened this issue Apr 11, 2020 · 5 comments

Comments

@TheAnimeSenpai
Copy link

i'm trying to use Jest testing framework along with strapi. The project itself works as expected but when attempting to run tests for it, it crashes.

Jest setup file

const path = require('path');

dotenv.config({ path: path.resolve(__dirname, `../../.env.test`)});

const strapi = require('strapi');
const request = require('supertest');

jest.setTimeout(15000);

beforeAll(done => {
  strapi.start({}, err => {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
    if(err) {
        return done(err);
    }

    done(err, strapi);
  });
});

afterAll(done => {
  strapi.stop(done());
});

Error Output Snippet

 FAIL  tests/controllers/sample.test.js
  ● Test suite failed to run

    TypeError: strapi.stop is not a function

      21 |
      22 | afterAll(done => {
    > 23 |   strapi.stop(done());
         |          ^
      24 | });

      at Object.<anonymous> (tests/config/setup.js:23:10)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        21.146s

Test File

describe('API - Sample', () => {
    test('get all samples', async () => {
      const response = await app
        .get('/samples')
        .expect(200);
  
      expect(response.body).not.toBeNull();
      expect(response.body.length).toBeGreaterThanOrEqual(3);
  
      //data here is the first object passed in the seed file.
      expect(response.body).toContainEqual({
        id: 1,
        username: expect.String('ichi'),
        createdAt: expect.any(String),
        updatedAt: expect.any(String)
      });
    });
});

Steps to reproduce the behavior

  1. Create a new project
  2. Configure Jest in package json
"jest": {
    "testEnvironment": "node",
    "setupFilesAfterEnv": [
      "<rootDir>/tests/config/setup.js"
    ],
    "testMatch": [
      "<rootDir>/tests/controllers/**/*.test.js"
    ]
  },
  1. Run tests and see error on power shell

Expected behavior
I expected the result of the test, either passing or failing.

System

  • Node.js version: 12.16.1
  • NPM version: 6.13.4
  • Strapi version: 3.0.0-alpha.13.1
  • Database: mysql
  • Operating system: Windows 10
@derrickmehaffy
Copy link
Member

Strapi version: 3.0.0-alpha.13.1 Strapi alpha is not supported

@TheAnimeSenpai
Copy link
Author

TheAnimeSenpai commented Apr 11, 2020

Hi @derrickmehaffy ...made a mistake on the version...
strapi version : Strapi v3.0.0-beta.19.5
Error is still the same

@derrickmehaffy
Copy link
Member

For reference this issue is about the missing strapi.stop and not about testing (which isn't a bug and should be directed to the "question" media like Stack Overflow/slack)

@qunabu
Copy link
Contributor

qunabu commented Apr 19, 2020

@lauriejim
Copy link
Contributor

Future guide on testing - #6361

@strapi strapi locked as resolved and limited conversation to collaborators Jun 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants