|
1 | 1 | import chai from 'chai'
|
2 | 2 | const expect = chai.expect
|
| 3 | +import Vue from 'vue' |
3 | 4 | import VueLogger from '../src/logger'
|
4 | 5 | const {print, validateOptions, initLoggerInstance, logLevels, install} = VueLogger()
|
5 | 6 |
|
6 | 7 | describe('Logger.js', () => {
|
7 | 8 |
|
| 9 | + describe('install()', () => { |
| 10 | + |
| 11 | + it('install() should work with the correct params.', () => { |
| 12 | + const options = { |
| 13 | + logLevel: 'debug', |
| 14 | + stringifyByDefault: false, |
| 15 | + showLogLevel: false, |
| 16 | + } |
| 17 | + |
| 18 | + Vue.use({install}, options) |
| 19 | + |
| 20 | + new Vue({ |
| 21 | + created() { |
| 22 | + expect(this.$log).to.be.a('object') |
| 23 | + expect(this.$log.debug).to.be.a('function') |
| 24 | + expect(this.$log.info).to.be.a('function') |
| 25 | + expect(this.$log.warn).to.be.a('function') |
| 26 | + expect(this.$log.error).to.be.a('function') |
| 27 | + expect(this.$log.fatal).to.be.a('function') |
| 28 | + } |
| 29 | + }) |
| 30 | + |
| 31 | + expect(Vue.$log).to.be.a('object') |
| 32 | + expect(Vue.$log.debug).to.be.a('function') |
| 33 | + expect(Vue.$log.info).to.be.a('function') |
| 34 | + expect(Vue.$log.warn).to.be.a('function') |
| 35 | + expect(Vue.$log.error).to.be.a('function') |
| 36 | + expect(Vue.$log.fatal).to.be.a('function') |
| 37 | + }) |
| 38 | + |
| 39 | + it('install() should throw an error with the an incorrect log level.', () => { |
| 40 | + const options = { |
| 41 | + logLevel: 'foo' |
| 42 | + } |
| 43 | + expect(() => { install(() => {}, options) }) |
| 44 | + .to |
| 45 | + .throw(Error, 'Provided options for vuejs-logger are not valid.') |
| 46 | + }) |
| 47 | + |
| 48 | + it('install() should throw an error with the an incorrect log level.', () => { |
| 49 | + const options = { |
| 50 | + logLevel: false |
| 51 | + } |
| 52 | + expect(() => { install(() => {}, options) }) |
| 53 | + .to |
| 54 | + .throw(Error, 'Provided options for vuejs-logger are not valid.') |
| 55 | + }) |
| 56 | + |
| 57 | + it('install() should throw an error with the an incorrect log level.', () => { |
| 58 | + const options = { |
| 59 | + logLevel: undefined |
| 60 | + } |
| 61 | + expect(() => { install(() => {}, options) }) |
| 62 | + .to |
| 63 | + .throw(Error, 'Provided options for vuejs-logger are not valid.') |
| 64 | + }) |
| 65 | + |
| 66 | + it('install() should throw an error with the an incorrect log level.', () => { |
| 67 | + const options = { |
| 68 | + logLevel: null |
| 69 | + } |
| 70 | + expect(() => { install(() => {}, options) }) |
| 71 | + .to |
| 72 | + .throw(Error, 'Provided options for vuejs-logger are not valid.') |
| 73 | + }) |
| 74 | + }) |
| 75 | + |
8 | 76 | describe('initLoggerInstance()', () => {
|
9 | 77 |
|
10 | 78 | it('initLoggerInstance() should ignore logLevels that are more restrictive than set logLevel.', () => {
|
@@ -71,61 +139,4 @@ describe('Logger.js', () => {
|
71 | 139 | print('debug', 'debug |', ['test'])
|
72 | 140 | })
|
73 | 141 | })
|
74 |
| - |
75 |
| - describe('install()', () => { |
76 |
| - |
77 |
| - it('install() should work with the correct params.', () => { |
78 |
| - const Vue = () => {} |
79 |
| - const options = { |
80 |
| - logLevel: 'debug', |
81 |
| - stringifyByDefault: false, |
82 |
| - showLogLevel: false, |
83 |
| - } |
84 |
| - install(Vue, options) |
85 |
| - Vue() |
86 |
| - |
87 |
| - expect(Vue.prototype.$log).to.be.a('object') |
88 |
| - expect(Vue.prototype.$log.debug).to.be.a('function') |
89 |
| - expect(Vue.prototype.$log.info).to.be.a('function') |
90 |
| - expect(Vue.prototype.$log.warn).to.be.a('function') |
91 |
| - expect(Vue.prototype.$log.error).to.be.a('function') |
92 |
| - expect(Vue.prototype.$log.fatal).to.be.a('function') |
93 |
| - }) |
94 |
| - |
95 |
| - it('install() should throw an error with the an incorrect log level.', () => { |
96 |
| - const options = { |
97 |
| - logLevel: 'foo' |
98 |
| - } |
99 |
| - expect(() => { install(() => {}, options) }) |
100 |
| - .to |
101 |
| - .throw(Error, 'Provided options for vuejs-logger are not valid.') |
102 |
| - }) |
103 |
| - |
104 |
| - it('install() should throw an error with the an incorrect log level.', () => { |
105 |
| - const options = { |
106 |
| - logLevel: false |
107 |
| - } |
108 |
| - expect(() => { install(() => {}, options) }) |
109 |
| - .to |
110 |
| - .throw(Error, 'Provided options for vuejs-logger are not valid.') |
111 |
| - }) |
112 |
| - |
113 |
| - it('install() should throw an error with the an incorrect log level.', () => { |
114 |
| - const options = { |
115 |
| - logLevel: undefined |
116 |
| - } |
117 |
| - expect(() => { install(() => {}, options) }) |
118 |
| - .to |
119 |
| - .throw(Error, 'Provided options for vuejs-logger are not valid.') |
120 |
| - }) |
121 |
| - |
122 |
| - it('install() should throw an error with the an incorrect log level.', () => { |
123 |
| - const options = { |
124 |
| - logLevel: null |
125 |
| - } |
126 |
| - expect(() => { install(() => {}, options) }) |
127 |
| - .to |
128 |
| - .throw(Error, 'Provided options for vuejs-logger are not valid.') |
129 |
| - }) |
130 |
| - }) |
131 | 142 | })
|
0 commit comments