From 7169d14179ee468dd42ab328d136e9ceb3796202 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 25 Apr 2016 13:17:59 -0400 Subject: [PATCH] update if tests --- package.json | 2 +- test/unit/features/directives/if.spec.js | 56 ++++++++++++++----- .../features/global-api/global-config.spec.js | 7 ++- test/unit/index.js | 4 ++ 4 files changed, 50 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index de8d5bb1..b6cd1e67 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "dev": "webpack --watch --config build/webpack.dist.dev.config.js", "dev-test": "karma start build/karma.dev.config.js", "dev-ssr": "webpack --watch --config build/webpack.ssr.dev.config.js", - "test": "npm run unit && npm run e2e", + "test": "npm run lint && npm run unit && npm run e2e", "build": "NODE_ENV=production node build/build.js", "lint": "eslint src build test", "unit": "karma start build/karma.unit.config.js", diff --git a/test/unit/features/directives/if.spec.js b/test/unit/features/directives/if.spec.js index 677a5071..73ca938e 100644 --- a/test/unit/features/directives/if.spec.js +++ b/test/unit/features/directives/if.spec.js @@ -5,7 +5,7 @@ describe('Directive v-if', () => { const vm = new Vue({ el: '#app', template: '
hello
', - data: {foo: true} + data: { foo: true } }) expect(vm.$el.innerHTML).toBe('hello') }) @@ -14,16 +14,16 @@ describe('Directive v-if', () => { const vm = new Vue({ el: '#app', template: '
hello
', - data: {foo: false} + data: { foo: false } }) expect(vm.$el.innerHTML).toBe('') }) - it('should update if value changed', (done) => { + it('should update if value changed', done => { const vm = new Vue({ el: '#app', template: '
hello
', - data: {foo: true} + data: { foo: true } }) expect(vm.$el.innerHTML).toBe('hello') vm.foo = false @@ -57,11 +57,16 @@ describe('Directive v-if', () => { }) }) - it('should work well with v-else', (done) => { + it('should work well with v-else', done => { const vm = new Vue({ el: '#app', - template: '
hellobye
', - data: {foo: true} + template: ` +
+ hello + bye +
+ `, + data: { foo: true } }) expect(vm.$el.innerHTML).toBe('hello') vm.foo = false @@ -95,18 +100,28 @@ describe('Directive v-if', () => { }) }) - it('should work well with v-for', (done) => { + it('should work well with v-for', done => { const vm = new Vue({ el: '#app', - template: '
{{i}}
', - data: {list: [{value: true}, {value: false}, {value: true}]} + template: ` +
+ {{i}} +
+ `, + data: { + list: [ + { value: true }, + { value: false }, + { value: true } + ] + } }) expect(vm.$el.innerHTML).toBe('02') vm.list[0].value = false setTimeout(() => { new Promise((res, rej) => { expect(vm.$el.innerHTML).toBe('2') - vm.list.push({value: true}) + vm.list.push({ value: true }) res() }).then(() => { expect(vm.$el.innerHTML).toBe('23') @@ -118,18 +133,29 @@ describe('Directive v-if', () => { }) }) - it('should work well with v-for and v-else', (done) => { + it('should work well with v-for and v-else', done => { const vm = new Vue({ el: '#app', - template: '
hellobye
', - data: {list: [{value: true}, {value: false}, {value: true}]} + template: ` +
+ hello + bye +
+ `, + data: { + list: [ + { value: true }, + { value: false }, + { value: true } + ] + } }) expect(vm.$el.innerHTML).toBe('hellobyehello') vm.list[0].value = false setTimeout(() => { new Promise((res, rej) => { expect(vm.$el.innerHTML).toBe('byebyehello') - vm.list.push({value: true}) + vm.list.push({ value: true }) res() }).then(() => { expect(vm.$el.innerHTML).toBe('byebyehellohello') diff --git a/test/unit/features/global-api/global-config.spec.js b/test/unit/features/global-api/global-config.spec.js index 2a7ecf0b..5eed5320 100644 --- a/test/unit/features/global-api/global-config.spec.js +++ b/test/unit/features/global-api/global-config.spec.js @@ -2,22 +2,23 @@ import Vue from 'vue' describe('Global config', () => { describe('preserveWhitespace', () => { - it('should be true by default', () => { + it('should preserve whitepspaces when set to true', () => { + // this option is set to false during unit tests. + Vue.config.preserveWhitespace = true const vm = new Vue({ el: document.createElement('div'), template: '
hi ha
' }) expect(vm.$el.innerHTML).toBe('hi ha') + Vue.config.preserveWhitespace = false }) it('should remove whitespaces when set to false', () => { - Vue.config.preserveWhitespace = false const vm = new Vue({ el: document.createElement('div'), template: '
hi ha
' }) expect(vm.$el.innerHTML).toBe('hiha') - Vue.config.preserveWhitespace = true }) }) diff --git a/test/unit/index.js b/test/unit/index.js index b204285f..e77c5745 100644 --- a/test/unit/index.js +++ b/test/unit/index.js @@ -1,3 +1,7 @@ +import Vue from 'vue' + +Vue.config.preserveWhitespace = false + if (typeof console === 'undefined') { window.console = { error: function () {}