diff --git a/packages/vue-compat/__tests__/compiler.spec.ts b/packages/vue-compat/__tests__/compiler.spec.ts index 2ae2f211a..8891e6607 100644 --- a/packages/vue-compat/__tests__/compiler.spec.ts +++ b/packages/vue-compat/__tests__/compiler.spec.ts @@ -16,7 +16,6 @@ afterEach(() => { Vue.configureCompat({ MODE: 3 }) }) -// COMPILER_V_FOR_REF is tested in ./refInfor.spec.ts // COMPILER_FILTERS is tested in ./filters.spec.ts test('COMPILER_IS_ON_ELEMENT', () => { diff --git a/packages/vue-compat/__tests__/warnDeprecation.spec.ts b/packages/vue-compat/__tests__/warnDeprecation.spec.ts new file mode 100644 index 000000000..5319b862e --- /dev/null +++ b/packages/vue-compat/__tests__/warnDeprecation.spec.ts @@ -0,0 +1,87 @@ +import Vue from '@vue/compat' +import { + DeprecationTypes, + deprecationData, + toggleDeprecationWarning, +} from '../../runtime-core/src/compat/compatConfig' + +beforeEach(() => { + toggleDeprecationWarning(true) + Vue.configureCompat({ + MODE: 2, + GLOBAL_MOUNT: 'suppress-warning', + }) +}) + +afterEach(() => { + toggleDeprecationWarning(false) + Vue.configureCompat({ MODE: 3 }) +}) + +describe('should warn deprecation while using compat', () => { + test('have no compat config', () => { + const vm = new Vue({ + template: `
hello
`, + }).$mount() + + expect(vm.$el).toBeInstanceOf(HTMLDivElement) + expect(vm.$el.outerHTML).toBe(`
hello
`) + + const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION] + .message as Function + expect(message('draggable', false, true)).toHaveBeenWarned() + }) + + test('set compat config to true', () => { + Vue.configureCompat({ + ATTR_ENUMERATED_COERCION: true, + }) + + const vm = new Vue({ + template: `
hello
`, + }).$mount() + + expect(vm.$el).toBeInstanceOf(HTMLDivElement) + expect(vm.$el.outerHTML).toBe(`
hello
`) + + const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION] + .message as Function + expect(message('draggable', false, true)).toHaveBeenWarned() + }) + + test('set compat config to "suppress-warning"', () => { + Vue.configureCompat({ + ATTR_ENUMERATED_COERCION: 'suppress-warning', + }) + + const vm = new Vue({ + template: `
hello
`, + }).$mount() + + expect(vm.$el).toBeInstanceOf(HTMLDivElement) + expect(vm.$el.outerHTML).toBe(`
hello
`) + + const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION] + .message as Function + expect(message('draggable', false, true)).not.toHaveBeenWarned() + expect(message('draggable', false, false)).not.toHaveBeenWarned() + }) + + test('set compat config to "suppress-warning"', () => { + Vue.configureCompat({ + ATTR_ENUMERATED_COERCION: false, + }) + + const vm = new Vue({ + template: `
hello
`, + }).$mount() + + expect(vm.$el).toBeInstanceOf(HTMLDivElement) + expect(vm.$el.outerHTML).toBe(`
hello
`) + + const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION] + .message as Function + expect(message('draggable', false, true)).not.toHaveBeenWarned() + expect(message('draggable', false, false)).not.toHaveBeenWarned() + }) +})