Skip to content

Commit

Permalink
chore: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
noootwo committed Nov 21, 2024
1 parent a5817ed commit cdc251e
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 1 deletion.
1 change: 0 additions & 1 deletion packages/vue-compat/__tests__/compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
87 changes: 87 additions & 0 deletions packages/vue-compat/__tests__/warnDeprecation.spec.ts
Original file line number Diff line number Diff line change
@@ -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: `<div draggable="false">hello</div>`,
}).$mount()

expect(vm.$el).toBeInstanceOf(HTMLDivElement)
expect(vm.$el.outerHTML).toBe(`<div draggable="true">hello</div>`)

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: `<div draggable="false">hello</div>`,
}).$mount()

expect(vm.$el).toBeInstanceOf(HTMLDivElement)
expect(vm.$el.outerHTML).toBe(`<div draggable="true">hello</div>`)

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: `<div draggable="false">hello</div>`,
}).$mount()

expect(vm.$el).toBeInstanceOf(HTMLDivElement)
expect(vm.$el.outerHTML).toBe(`<div draggable="true">hello</div>`)

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: `<div draggable="false">hello</div>`,
}).$mount()

expect(vm.$el).toBeInstanceOf(HTMLDivElement)
expect(vm.$el.outerHTML).toBe(`<div draggable="false">hello</div>`)

const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
.message as Function
expect(message('draggable', false, true)).not.toHaveBeenWarned()
expect(message('draggable', false, false)).not.toHaveBeenWarned()
})
})

0 comments on commit cdc251e

Please sign in to comment.