log.test.js
2.34 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var chai = require('chai')
, sinonChai = require("sinon-chai")
, sinon = require('sinon')
, fs = require('fs')
, path = require('path')
, expect = chai.expect
, assert = chai.assert
, Support = require(__dirname + '/../support')
chai.use(sinonChai)
chai.config.includeStack = true
describe(Support.getTestDialectTeaser("Sequelize"), function () {
describe('log', function() {
beforeEach(function() {
this.spy = sinon.spy(console, 'log')
})
afterEach(function() {
console.log.restore()
})
describe("with disabled logging", function() {
beforeEach(function() {
this.sequelize = new Support.Sequelize('db', 'user', 'pw', { logging: false })
})
it("does not call the log method of the logger", function() {
this.sequelize.log()
expect(this.spy.calledOnce).to.be.false
})
})
describe('with default logging options', function() {
beforeEach(function() {
this.sequelize = new Support.Sequelize('db', 'user', 'pw')
})
describe("called with no arguments", function() {
it('calls the log method', function() {
this.sequelize.log()
expect(this.spy.calledOnce).to.be.true
})
it('logs an empty string as info event', function() {
this.sequelize.log()
expect(this.spy.calledOnce).to.be.true
})
})
describe("called with one argument", function() {
it('logs the passed string as info event', function() {
this.sequelize.log('my message')
expect(this.spy.withArgs('my message').calledOnce).to.be.true
})
})
describe("called with more than two arguments", function() {
it("passes the arguments to the logger", function() {
this.sequelize.log('error', 'my message', 1, { a: 1 })
expect(this.spy.withArgs('error', 'my message', 1, { a: 1 }).calledOnce).to.be.true
})
})
})
describe("with a custom function for logging", function() {
beforeEach(function() {
this.spy = sinon.spy()
this.sequelize = new Support.Sequelize('db', 'user', 'pw', { logging: this.spy })
})
it("calls the custom logger method", function() {
this.sequelize.log('om nom')
expect(this.spy.calledOnce).to.be.true
})
})
})
})