11import { createLocalVue , mount } from '@vue/test-utils' ;
22import createNumberMask from 'text-mask-addons/dist/createNumberMask' ;
3- import VueMask , { VueMaskDirective , VueMaskPlugin } from '../index' ;
3+ import VueMask , { VueMaskDirective , VueMaskPlugin , VueMaskFilter } from '../index' ;
44import { timeRangeMask } from '../utils/timeRangeMask' ;
55
66describe ( 'plugin/directive registration' , ( ) => {
@@ -18,10 +18,20 @@ describe('plugin/directive registration', () => {
1818 expect ( VueMaskPlugin ) . toEqual ( expect . any ( Function ) ) ;
1919 } ) ;
2020
21+ it ( 'named export `VueMaskFilter` should be a function' , ( ) => {
22+ expect ( VueMaskFilter ) . toEqual ( expect . any ( Function ) ) ;
23+ } ) ;
24+
2125 it ( 'named export `VueMaskDirective` should be an object' , ( ) => {
2226 expect ( VueMaskDirective ) . toEqual ( expect . any ( Object ) ) ;
2327 } ) ;
2428
29+ it ( 'should register `VMask` filter' , ( ) => {
30+ expect ( Vue . options . filters . VMask ) . toBeUndefined ( ) ;
31+ Vue . use ( VueMask ) ;
32+ expect ( Vue . options . filters . VMask ) . toEqual ( expect . any ( Function ) ) ;
33+ } ) ;
34+
2535 it ( 'should register `v-mask` directive' , ( ) => {
2636 expect ( Vue . options . directives . mask ) . toBeUndefined ( ) ;
2737 Vue . use ( VueMask ) ;
@@ -234,3 +244,43 @@ describe('directive usage', () => {
234244 expect ( wrapper . vm . $el . value ) . toBe ( '19:32' ) ;
235245 } ) ;
236246} ) ;
247+
248+ describe ( 'filter usage' , ( ) => {
249+ let mountWithMask ;
250+
251+ beforeEach ( ( ) => {
252+ const localVue = createLocalVue ( ) ;
253+ localVue . use ( VueMask ) ;
254+ mountWithMask = ( arg , options ) => mount ( arg , { ...options , localVue } ) ;
255+ } ) ;
256+
257+ it ( 'should mask static string' , ( ) => {
258+ const wrapper = mountWithMask ( {
259+ template : '<span>{{ "9999999999" | VMask("(###) ###-####") }}</span>' ,
260+ } ) ;
261+ expect ( wrapper . text ( ) ) . toBe ( '(999) 999-9999' ) ;
262+ } ) ;
263+
264+ it ( 'should mask static number' , ( ) => {
265+ const wrapper = mountWithMask ( {
266+ template : '<span>{{ 9999999999 | VMask("(###) ###-####") }}</span>' ,
267+ } ) ;
268+ expect ( wrapper . text ( ) ) . toBe ( '(999) 999-9999' ) ;
269+ } ) ;
270+
271+ it ( 'should mask dynamic value' , ( ) => {
272+ const wrapper = mountWithMask ( {
273+ data : ( ) => ( { val : '8888888888' } ) ,
274+ template : '<span>{{ val | VMask("(###) ###-####") }}</span>' ,
275+ } ) ;
276+ expect ( wrapper . text ( ) ) . toBe ( '(888) 888-8888' ) ;
277+ } ) ;
278+
279+ it . each ( [ null , undefined ] ) ( 'should pass through %p without modification' , ( val ) => {
280+ const wrapper = mountWithMask ( {
281+ data : ( ) => ( { val } ) ,
282+ template : '<span>{{ val | VMask("(###) ###-####") }}</span>' ,
283+ } ) ;
284+ expect ( wrapper . text ( ) ) . toBe ( '' ) ;
285+ } ) ;
286+ } ) ;
0 commit comments