wip: test for global filter registration
This commit is contained in:
parent
bd3cc4d2c7
commit
324a00c85d
@ -96,7 +96,7 @@ export type CompatVue = Pick<App, 'version' | 'component' | 'directive'> & {
|
|||||||
/**
|
/**
|
||||||
* @deprecated filters have been removed from Vue 3.
|
* @deprecated filters have been removed from Vue 3.
|
||||||
*/
|
*/
|
||||||
filter(name: string, arg: any): null
|
filter(name: string, arg?: any): null
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@ -138,7 +138,7 @@ export function createCompatVue(
|
|||||||
const app = createApp(options)
|
const app = createApp(options)
|
||||||
|
|
||||||
// copy over asset registries and deopt flag
|
// copy over asset registries and deopt flag
|
||||||
;['mixins', 'components', 'directives', 'deopt'].forEach(key => {
|
;['mixins', 'components', 'directives', 'filters', 'deopt'].forEach(key => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
app._context[key] = singletonApp._context[key]
|
app._context[key] = singletonApp._context[key]
|
||||||
})
|
})
|
||||||
@ -312,9 +312,13 @@ export function createCompatVue(
|
|||||||
}
|
}
|
||||||
}) as any
|
}) as any
|
||||||
|
|
||||||
Vue.filter = ((name: string, filter: any) => {
|
Vue.filter = ((name: string, filter?: any) => {
|
||||||
// TODO deprecation warning
|
if (filter) {
|
||||||
// TODO compiler warning for filters (maybe behavior compat?)
|
singletonApp.filter!(name, filter)
|
||||||
|
return Vue
|
||||||
|
} else {
|
||||||
|
return singletonApp.filter!(name)
|
||||||
|
}
|
||||||
}) as any
|
}) as any
|
||||||
|
|
||||||
// internal utils - these are technically internal but some plugins use it.
|
// internal utils - these are technically internal but some plugins use it.
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
import Vue from '@vue/compat'
|
import Vue from '@vue/compat'
|
||||||
import { CompilerDeprecationTypes } from '../../compiler-core/src'
|
import { CompilerDeprecationTypes } from '../../compiler-core/src'
|
||||||
import { toggleDeprecationWarning } from '../../runtime-core/src/compat/compatConfig'
|
import {
|
||||||
|
deprecationData,
|
||||||
|
DeprecationTypes,
|
||||||
|
toggleDeprecationWarning
|
||||||
|
} from '../../runtime-core/src/compat/compatConfig'
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
toggleDeprecationWarning(false)
|
toggleDeprecationWarning(false)
|
||||||
Vue.configureCompat({ MODE: 2 })
|
Vue.configureCompat({ MODE: 2, GLOBAL_MOUNT: 'suppress-warning' })
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -32,6 +36,22 @@ describe('FILTERS', () => {
|
|||||||
return v * 2
|
return v * 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it('global registration', () => {
|
||||||
|
toggleDeprecationWarning(true)
|
||||||
|
Vue.filter('globalUpper', upper)
|
||||||
|
expect(Vue.filter('globalUpper')).toBe(upper)
|
||||||
|
const vm = new Vue({
|
||||||
|
template: '<div>{{ msg | globalUpper }}</div>',
|
||||||
|
data: () => ({
|
||||||
|
msg: 'hi'
|
||||||
|
})
|
||||||
|
}).$mount()
|
||||||
|
expect(vm.$el.textContent).toBe('HI')
|
||||||
|
expect(deprecationData[DeprecationTypes.FILTERS].message).toHaveBeenWarned()
|
||||||
|
expect(CompilerDeprecationTypes.COMPILER_FILTERS).toHaveBeenWarned()
|
||||||
|
Vue.filter('globalUpper', undefined)
|
||||||
|
})
|
||||||
|
|
||||||
it('basic usage', () => {
|
it('basic usage', () => {
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
template: '<div>{{ msg | upper }}</div>',
|
template: '<div>{{ msg | upper }}</div>',
|
||||||
|
Loading…
Reference in New Issue
Block a user