@@ -4,11 +4,14 @@ var nextTick = Vue.nextTick
4
4
5
5
describe ( 'Directive' , function ( ) {
6
6
7
- var el = { } // simply a mock to be able to run in Node
8
- var vm , def
9
-
7
+ var el , vm , def
10
8
beforeEach ( function ( ) {
9
+ el = document . createElement ( 'div' )
11
10
def = {
11
+ params : [ 'foo' ] ,
12
+ paramWatchers : {
13
+ foo : jasmine . createSpy ( 'foo' )
14
+ } ,
12
15
bind : jasmine . createSpy ( 'bind' ) ,
13
16
update : jasmine . createSpy ( 'update' ) ,
14
17
unbind : jasmine . createSpy ( 'unbind' )
@@ -154,4 +157,32 @@ describe('Directive', function () {
154
157
expect ( d . update ) . toBe ( def . update )
155
158
expect ( def . update ) . toHaveBeenCalled ( )
156
159
} )
160
+
161
+ it ( 'static params' , function ( ) {
162
+ el . setAttribute ( 'foo' , 'hello' )
163
+ var d = new Directive ( {
164
+ name : 'test' ,
165
+ def : def ,
166
+ expression : 'a'
167
+ } , vm , el )
168
+ d . _bind ( )
169
+ expect ( d . params . foo ) . toBe ( 'hello' )
170
+ } )
171
+
172
+ it ( 'dynamic params' , function ( done ) {
173
+ el . setAttribute ( ':foo' , 'a' )
174
+ var d = new Directive ( {
175
+ name : 'test' ,
176
+ def : def ,
177
+ expression : 'a'
178
+ } , vm , el )
179
+ d . _bind ( )
180
+ expect ( d . params . foo ) . toBe ( vm . a )
181
+ vm . a = 2
182
+ nextTick ( function ( ) {
183
+ expect ( def . paramWatchers . foo ) . toHaveBeenCalledWith ( 2 , 1 )
184
+ expect ( d . params . foo ) . toBe ( vm . a )
185
+ done ( )
186
+ } )
187
+ } )
157
188
} )
0 commit comments