File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { DirectiveBinding } from 'vue/types/options'
2
2
import { VNode } from 'vue/types/vnode'
3
+ import { warn } from './util/warn'
3
4
4
5
interface FluentDirectiveBinding {
5
6
key : string
@@ -13,8 +14,13 @@ export default {
13
14
return
14
15
}
15
16
16
- const directiveData = binding . value as FluentDirectiveBinding
17
+ if ( binding . arg === undefined ) {
18
+ warn ( false , 'v-t directive is missing arg with translation key' )
19
+ return
20
+ }
21
+
22
+ const directiveData = ( binding . value as FluentDirectiveBinding ) || { }
17
23
18
- el . textContent = vnode . context . $t ( directiveData . key , directiveData . arg )
24
+ el . textContent = vnode . context . $t ( binding . arg , directiveData . arg )
19
25
}
20
26
}
Original file line number Diff line number Diff line change 3
3
exports [` directive can use parameters 1` ] = ` <a href = " /foo" >Hello John</a >` ;
4
4
5
5
exports [` directive translates text content 1` ] = ` <a href = " /foo" >Link text</a >` ;
6
+
7
+ exports [` directive warns about missing key arg 1` ] = ` <a href = " /foo" >Fallback text</a >` ;
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ describe('directive', () => {
39
39
data : ( ) => ( {
40
40
name : 'John'
41
41
} ) ,
42
- template : `<a v-t="{ key: ' link' }" href="/foo">Fallback text</a>`
42
+ template : `<a v-t: link href="/foo">Fallback text</a>`
43
43
}
44
44
45
45
// Act
@@ -49,6 +49,23 @@ describe('directive', () => {
49
49
expect ( mounted ) . toMatchSnapshot ( )
50
50
} )
51
51
52
+ it ( 'warns about missing key arg' , ( ) => {
53
+ // Arrange
54
+ const component = {
55
+ template : `<a v-t href="/foo">Fallback text</a>`
56
+ }
57
+
58
+ const warn = jest . fn ( )
59
+ console . warn = warn
60
+
61
+ // Act
62
+ const mounted = mount ( component , options )
63
+
64
+ // Assert
65
+ expect ( mounted ) . toMatchSnapshot ( )
66
+ expect ( warn ) . toHaveBeenCalledTimes ( 1 )
67
+ } )
68
+
52
69
it ( 'can use parameters' , ( ) => {
53
70
// Arrange
54
71
bundle . addResource (
@@ -61,7 +78,7 @@ describe('directive', () => {
61
78
data : ( ) => ( {
62
79
name : 'John'
63
80
} ) ,
64
- template : `<a v-t="{ key: 'link', arg: { name: 'John' } }" href="/foo">Fallback text</a>`
81
+ template : `<a v-t:link ="{ arg: { name: 'John' } }" href="/foo">Fallback text</a>`
65
82
}
66
83
67
84
// Act
You can’t perform that action at this time.
0 commit comments