mardi 30 octobre 2018

EADDRINUSE :::8080 in jest

I know this error means that port 8080 is already in use but I also tried a different port but I am still getting the same errors for some specific tests only.

This is the code of one of those test

  describe("GET /", () => {
    it("should return all genres", async() => {
      await Genre.collection.insertMany([
        {name: 'genre1'},
        {name: 'genre2'}
      ]);

      const res = await request(server).get('/api/genres');
      expect(res.status).toBe(200);
      expect(res.body.length).toBe(2);
      expect(res.body.some( g => g.name === 'genre1')).toBeTruthy();
      expect(res.body.some( g => g.name === 'genre2')).toBeTruthy();
    });
  });

Any way to solve this error?

Aucun commentaire:

Enregistrer un commentaire