warning.test.js
1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const chai = require('chai');
const expect = chai.expect;
const Support = require('../../../support');
const Sequelize = Support.Sequelize;
const dialect = Support.getTestDialect();
const sinon = require('sinon');
describe(Support.getTestDialectTeaser('Warning'), () => {
// We can only test MySQL warnings when using MySQL.
if (dialect === 'mysql') {
describe('logging', () => {
it('logs warnings when there are warnings', async () => {
const logger = sinon.spy(console, 'log');
const sequelize = Support.createSequelizeInstance({
logging: logger,
benchmark: false,
showWarnings: true
});
const Model = sequelize.define('model', {
name: Sequelize.DataTypes.STRING(1, true)
});
await sequelize.sync({ force: true });
await sequelize.authenticate();
await sequelize.query("SET SESSION sql_mode='';");
await Model.create({
name: 'very-long-long-name'
});
// last log is warning message
expect(logger.args[logger.args.length - 1][0]).to.be.match(/^MySQL Warnings \(default\):.*/m);
logger.restore();
});
});
}
});