Test error with Jest and Supertest

Asked

Viewed 214 times

0

Good afternoon, you guys;

I created my tests with Jest and supertest, and they are giving an error "Object.is Equality",

Versão Node: 12.18.3
Versão NPM: 6.14.4
Versão Yarn: 1.22.4

ps: I am using Sqlite and Sequelize, besides being using Sucrase, and Express;

My configuration of Jest:

module.exports = {
  // Stop running tests after `n` failures
  bail: 1,

  // Automatically clear mock calls and instances between every test
  clearMocks: true,

  // Indicates whether the coverage information should be collected while executing the test
  collectCoverage: true,

  // An array of glob patterns indicating a set of files for which coverage information should be collected
  collectCoverageFrom: ['src/app/**/*.js'],

  // The directory where Jest should output its coverage files
  coverageDirectory: '__tests__/coverage',

  // A list of reporter names that Jest uses when writing coverage reports
  coverageReporters: ['text', 'lcov'],

  // The test environment that will be used for testing
  testEnvironment: 'node',

  // The glob patterns Jest uses to detect test files
  testMatch: ['**/__tests__/**/*.test.js'],

  // A map from regular expressions to paths to transformers
  transform: {
    '.(js|jsx|ts|tsx)': '@sucrase/jest-plugin',
  },
};

my Mill.test.js:

import request from 'supertest';
import server from '../../src/app';

describe('Mill Endpoints', () => {
  it('should be able to create a new mill', async () => {
    const response = await request(server)
      .post('/mills')
      .send({
        name: 'mill1',
      });
    expect(response.status).toBe(201);
    expect(response.body).toHaveProperty('id');
  });
});

My controller responsible for creating:

async createMill(request, response) {
    const millExists = await Mill.findOne({
      where: { name: request.body.name },
    });

    if (millExists) {
      return response.status(401).json({ error: 'Mill already exists' });
    }

    const { id, name } = await Mill.create(request.body);

    return response.status(201).json({ id, name });
  }

and my Validator:

try {
    const schema = Yup.object().shape({
      name: Yup.string().min(5).max(15).required(),
    });

    await schema.validate(request.body, { abortEarly: false });

    return next();
  } catch ({ errors }) {
    return response.format({ type: 'validation', errors }, 400);
  }

test error

sequelize err

1 answer

0

Problem was in setting up Sequelize pro Sqlite, which had no underscored and underscored configuration

Browser other questions tagged

You are not signed in. Login or sign up in order to post.