Skip to content

Commit 208678b

Browse files
committed
use custom matcher for warning tests
1 parent ccd11fb commit 208678b

27 files changed

+107
-131
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"eslint-plugin-promise": "^1.0.8",
5757
"eslint-plugin-standard": "^1.3.2",
5858
"istanbul-instrumenter-loader": "^0.1.3",
59-
"jasmine-core": "^2.3.4",
59+
"jasmine-core": "^2.4.1",
6060
"karma": "^0.13.8",
6161
"karma-chrome-launcher": "^0.2.0",
6262
"karma-coverage": "^0.5.0",

test/unit/specs/api/data_spec.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var nextTick = _.nextTick
55
describe('Data API', function () {
66
var vm
77
beforeEach(function () {
8-
spyWarns()
98
vm = new Vue({
109
data: {
1110
a: 1,
@@ -33,7 +32,7 @@ describe('Data API', function () {
3332
expect(vm.$get('c')).toBeUndefined()
3433
// invalid, should warn
3534
vm.$get('a(')
36-
expect(hasWarned('Invalid expression')).toBe(true)
35+
expect('Invalid expression').toHaveBeenWarned()
3736
})
3837

3938
it('$set', function () {
@@ -45,12 +44,12 @@ describe('Data API', function () {
4544
vm.$set('c.d', 2)
4645
expect(vm.c.d).toBe(2)
4746
// warn against setting unexisting
48-
expect(hasWarned('Consider pre-initializing')).toBe(true)
47+
expect('Consider pre-initializing').toHaveBeenWarned()
4948
})
5049

5150
it('$set invalid', function () {
5251
vm.$set('c + d', 1)
53-
expect(hasWarned('Invalid setter expression')).toBe(true)
52+
expect('Invalid setter expression').toHaveBeenWarned()
5453
})
5554

5655
it('$delete', function () {

test/unit/specs/api/lifecycle_spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ describe('Lifecycle API', function () {
99
el.textContent = '{{test}}'
1010
frag = document.createDocumentFragment()
1111
frag.appendChild(el)
12-
spyWarns()
1312
})
1413

1514
it('normal', function () {
@@ -53,7 +52,7 @@ describe('Lifecycle API', function () {
5352
it('warn invalid selector', function () {
5453
var vm = new Vue()
5554
vm.$mount('#none-exist')
56-
expect(hasWarned('Cannot find element')).toBe(true)
55+
expect('Cannot find element').toHaveBeenWarned()
5756
})
5857

5958
it('replace', function () {
@@ -141,7 +140,7 @@ describe('Lifecycle API', function () {
141140
el: el
142141
})
143142
vm.$mount(el)
144-
expect(hasWarned('$mount() should be called only once')).toBe(true)
143+
expect('$mount() should be called only once').toHaveBeenWarned()
145144
})
146145
})
147146

test/unit/specs/async_component_spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe('Async components', function () {
66
beforeEach(function () {
77
el = document.createElement('div')
88
document.body.appendChild(el)
9-
spyWarns()
109
})
1110

1211
afterEach(function () {
@@ -199,7 +198,7 @@ describe('Async components', function () {
199198
}
200199
}
201200
})
202-
expect(hasWarned('Reason: nooooo')).toBe(true)
201+
expect('Reason: nooooo').toHaveBeenWarned()
203202
})
204203

205204
it('v-for', function (done) {

test/unit/specs/batcher_spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe('Batcher', function () {
66
var spy
77
beforeEach(function () {
88
spy = jasmine.createSpy('batcher')
9-
spyWarns()
109
})
1110

1211
it('pushWatcher', function (done) {
@@ -93,7 +92,7 @@ describe('Batcher', function () {
9392
batcher.pushWatcher(job)
9493
nextTick(function () {
9594
expect(count).toBe(config._maxUpdateCount + 1)
96-
expect(hasWarned('infinite update loop')).toBe(true)
95+
expect('infinite update loop').toHaveBeenWarned()
9796
done()
9897
})
9998
})

test/unit/specs/compiler/compile_spec.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ describe('Compile', function () {
4646
spyOn(vm, '_bindDir').and.callThrough()
4747
spyOn(vm, '$eval').and.callThrough()
4848
spyOn(vm, '$interpolate').and.callThrough()
49-
spyWarns()
5049
})
5150

5251
it('normal directives', function () {
@@ -327,7 +326,7 @@ describe('Compile', function () {
327326
expect(prop.parentPath).toBe('a')
328327
expect(prop.mode).toBe(bindingModes.TWO_WAY)
329328
// two way warn
330-
expect(hasWarned('non-settable parent path')).toBe(true)
329+
expect('non-settable parent path').toHaveBeenWarned()
331330
// literal with filter
332331
args = vm._bindDir.calls.argsFor(3)
333332
prop = args[0].prop
@@ -585,7 +584,7 @@ describe('Compile', function () {
585584
}
586585
})
587586
expect(el.innerHTML).toBe('<div></div>')
588-
expect(hasWarned('attribute interpolation is not allowed in Vue.js directives')).toBe(true)
587+
expect('attribute interpolation is not allowed in Vue.js directives').toHaveBeenWarned()
589588
})
590589

591590
it('attribute interpolation: warn mixed usage with v-bind', function () {
@@ -596,7 +595,7 @@ describe('Compile', function () {
596595
a: 'hi'
597596
}
598597
})
599-
expect(hasWarned('Do not mix mustache interpolation and v-bind')).toBe(true)
598+
expect('Do not mix mustache interpolation and v-bind').toHaveBeenWarned()
600599
})
601600

602601
it('warn directives on fragment instances', function () {
@@ -612,10 +611,10 @@ describe('Compile', function () {
612611
}
613612
})
614613
expect(getWarnCount()).toBe(1)
615-
expect(
616-
hasWarned('Attributes "id", "class" are ignored on component <test>', true) ||
617-
hasWarned('Attributes "class", "id" are ignored on component <test>')
618-
).toBe(true)
614+
expect([
615+
'Attributes "id", "class" are ignored on component <test>',
616+
'Attributes "class", "id" are ignored on component <test>'
617+
]).toHaveBeenWarned()
619618
})
620619

621620
it('should compile component container directives using correct context', function () {

test/unit/specs/compiler/transclude_spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ describe('Transclude', function () {
77
beforeEach(function () {
88
el = document.createElement('div')
99
options = _.extend({}, Vue.options)
10-
spyWarns()
1110
})
1211

1312
it('normal', function () {
@@ -26,7 +25,7 @@ describe('Transclude', function () {
2625
options.template = '#non-existent-stuff'
2726
var res = transclude(el, options)
2827
expect(res).toBeUndefined()
29-
expect(hasWarned('Invalid template option')).toBe(true)
28+
expect('Invalid template option').toHaveBeenWarned()
3029
})
3130

3231
it('template replace', function () {

test/unit/specs/directives/element/slot_spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var nextTick = Vue.nextTick
44
describe('Slot Distribution', function () {
55
var el, vm, options
66
beforeEach(function () {
7-
spyWarns()
87
el = document.createElement('div')
98
options = {
109
el: el,
@@ -140,7 +139,7 @@ describe('Slot Distribution', function () {
140139
theName: 'two'
141140
}
142141
mount()
143-
expect(hasWarned('slot names cannot be dynamic')).toBe(true)
142+
expect('slot names cannot be dynamic').toHaveBeenWarned()
144143
})
145144

146145
it('content should be dynamic and compiled in parent scope', function (done) {

test/unit/specs/directives/internal/component_spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe('Component', function () {
66
beforeEach(function () {
77
el = document.createElement('div')
88
document.body.appendChild(el)
9-
spyWarns()
109
})
1110

1211
afterEach(function () {
@@ -519,7 +518,7 @@ describe('Component', function () {
519518
new Vue({
520519
el: el
521520
})
522-
expect(hasWarned('cannot mount component "test" on already mounted element')).toBe(true)
521+
expect('cannot mount component "test" on already mounted element').toHaveBeenWarned()
523522
})
524523

525524
it('not found component should not throw', function () {
@@ -539,6 +538,6 @@ describe('Component', function () {
539538
'hello-world': {}
540539
}
541540
})
542-
expect(hasWarned('did you mean <hello-world>?')).toBe(true)
541+
expect('did you mean <hello-world>?').toHaveBeenWarned()
543542
})
544543
})

0 commit comments

Comments
 (0)