Нужно подключить mock
require('dotenv').config();
const express = require('express');
const request = require('supertest');
const bodyParser = require('body-parser');
const redisMock = require('redis-mock');
const redis = require('redis');
const auth = require('../../../../server/controllers/auth');
const { i18next, i18nextMiddleware } = require('../../../i18n-server');
jest.spyOn(redis, 'createClient').mockImplementation(redisMock.createClient);
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(i18nextMiddleware);
app.post(
'/',
(req, res, next) => {
if (req.body.id && req.body.type) {
req.user = {
id: req.body.id,
type: req.body.type
};
}
next();
},
auth.signOut
);
describe('signOut', () => {
it('success', done => {
i18next.on('initialized', () => {
request(app)
.post('/')
.set('Accept-Language', 'en')
.type('application/x-www-form-urlencoded')
.send({
id: 1,
type: 'manager'
})
.end((err, res) => {
if (err) return done(err);
expect(res.status).toBe(200);
expect(res.body.result).toBe('ok');
done();
});
});
});
afterAll(() => {
redis.closeInstance();
});
});