11import Component , { createDecorator } from '../lib/index'
2- import { expect } from 'chai'
2+ import chai , { expect } from 'chai'
3+ import spies from 'chai-spies'
34import Vue from 'vue'
45
6+ chai . use ( spies )
7+
58describe ( 'vue-class-component with Babel' , ( ) => {
69 it ( 'should be instantiated without any errors' , ( ) => {
710 @Component
@@ -10,12 +13,21 @@ describe('vue-class-component with Babel', () => {
1013 } )
1114
1215 it ( 'should collect class properties as data' , ( ) => {
13- @Component
14- class MyComp {
16+ @Component ( {
17+ props : [ 'propValue' ]
18+ } )
19+ class MyComp extends Vue {
1520 foo = 'hello'
21+ bar = 1 + this . propValue
1622 }
17- const c = new MyComp ( )
23+ const c = new MyComp ( {
24+ propsData : {
25+ propValue : 1
26+ }
27+ } )
1828 expect ( c . foo ) . to . equal ( 'hello' )
29+ expect ( c . propValue ) . to . equal ( 1 )
30+ expect ( c . bar ) . to . equal ( 2 )
1931 } )
2032
2133 it ( 'should not collect uninitialized class properties' , ( ) => {
@@ -35,4 +47,26 @@ describe('vue-class-component with Babel', () => {
3547 expect ( 'foo' in c . $data ) . to . be . false
3648 expect ( 'bar' in c . $data ) . to . be . false
3749 } )
50+
51+ it ( 'warn if class property is used without inheriting Vue class' , ( ) => {
52+ const spy = chai . spy . on ( console , 'warn' )
53+
54+ @Component ( {
55+ foo : Number
56+ } )
57+ class MyComp {
58+ bar = this . foo + 2
59+ }
60+ const c = new MyComp ( {
61+ propsData : {
62+ foo : 1
63+ }
64+ } )
65+
66+ const message = '[vue-class-component] ' +
67+ 'Component class must inherit Vue or its descendant class ' +
68+ 'when class property is used.'
69+
70+ expect ( spy ) . to . have . been . called . with ( message )
71+ } )
3872} )
0 commit comments