chore: update test

This commit is contained in:
NoTwoBoy 2024-11-21 11:20:46 +08:00
parent c5eefdeed6
commit 05f5af49b1
3 changed files with 41 additions and 152 deletions

View File

@ -80,13 +80,12 @@ export function compatCoerceAttr(
} else if ( } else if (
value === false && value === false &&
!isSpecialBooleanAttr(key) && !isSpecialBooleanAttr(key) &&
compatUtils.isCompatEnabled(DeprecationTypes.ATTR_FALSE_VALUE, instance) compatUtils.softAssertCompatEnabled(
) {
compatUtils.warnDeprecation(
DeprecationTypes.ATTR_FALSE_VALUE, DeprecationTypes.ATTR_FALSE_VALUE,
instance, instance,
key, key,
) )
) {
el.removeAttribute(key) el.removeAttribute(key)
return true return true
} }

View File

@ -158,35 +158,17 @@ test('CUSTOM_DIR', async () => {
expect(getCalls()).toMatchObject([1, 1, 0, 0, 0]) expect(getCalls()).toMatchObject([1, 1, 0, 0, 0])
expect( const message = deprecationData[DeprecationTypes.CUSTOM_DIR]
(deprecationData[DeprecationTypes.CUSTOM_DIR].message as Function)( .message as Function
'bind', expect(message('bind', 'beforeMount')).toHaveBeenWarned()
'beforeMount', expect(message('inserted', 'mounted')).toHaveBeenWarned()
),
).toHaveBeenWarned()
expect(
(deprecationData[DeprecationTypes.CUSTOM_DIR].message as Function)(
'inserted',
'mounted',
),
).toHaveBeenWarned()
vm.foo++ vm.foo++
await nextTick() await nextTick()
expect(getCalls()).toMatchObject([1, 1, 1, 1, 0]) expect(getCalls()).toMatchObject([1, 1, 1, 1, 0])
expect( expect(message('update', 'updated')).toHaveBeenWarned()
(deprecationData[DeprecationTypes.CUSTOM_DIR].message as Function)( expect(message('componentUpdated', 'updated')).toHaveBeenWarned()
'update',
'updated',
),
).toHaveBeenWarned()
expect(
(deprecationData[DeprecationTypes.CUSTOM_DIR].message as Function)(
'componentUpdated',
'updated',
),
).toHaveBeenWarned()
}) })
test('ATTR_FALSE_VALUE', () => { test('ATTR_FALSE_VALUE', () => {
@ -196,16 +178,28 @@ test('ATTR_FALSE_VALUE', () => {
expect(vm.$el).toBeInstanceOf(HTMLDivElement) expect(vm.$el).toBeInstanceOf(HTMLDivElement)
expect(vm.$el.hasAttribute('id')).toBe(false) expect(vm.$el.hasAttribute('id')).toBe(false)
expect(vm.$el.hasAttribute('foo')).toBe(false) expect(vm.$el.hasAttribute('foo')).toBe(false)
expect(
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)( const message = deprecationData[DeprecationTypes.ATTR_FALSE_VALUE]
'id', .message as Function
), expect(message('id')).toHaveBeenWarned()
).toHaveBeenWarned() expect(message('foo')).toHaveBeenWarned()
expect( })
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
'foo', test(`ATTR_FALSE_VALUE with 'suppress-warning' value shouldn't throw warning`, () => {
), const vm = new Vue({
).toHaveBeenWarned() template: `<div :id="false" :foo="false"/>`,
compatConfig: {
ATTR_FALSE_VALUE: 'suppress-warning',
},
}).$mount()
expect(vm.$el).toBeInstanceOf(HTMLDivElement)
expect(vm.$el.hasAttribute('id')).toBe(false)
expect(vm.$el.hasAttribute('foo')).toBe(false)
const message = deprecationData[DeprecationTypes.ATTR_FALSE_VALUE]
.message as Function
expect(message('id')).not.toHaveBeenWarned()
expect(message('foo')).not.toHaveBeenWarned()
}) })
test("ATTR_FALSE_VALUE with false value shouldn't throw warning", () => { test("ATTR_FALSE_VALUE with false value shouldn't throw warning", () => {
@ -221,16 +215,11 @@ test("ATTR_FALSE_VALUE with false value shouldn't throw warning", () => {
expect(vm.$el.getAttribute('id')).toBe('false') expect(vm.$el.getAttribute('id')).toBe('false')
expect(vm.$el.hasAttribute('foo')).toBe(true) expect(vm.$el.hasAttribute('foo')).toBe(true)
expect(vm.$el.getAttribute('foo')).toBe('false') expect(vm.$el.getAttribute('foo')).toBe('false')
expect(
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)( const message = deprecationData[DeprecationTypes.ATTR_FALSE_VALUE]
'id', .message as Function
), expect(message('id')).not.toHaveBeenWarned()
).not.toHaveBeenWarned() expect(message('foo')).not.toHaveBeenWarned()
expect(
(deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
'foo',
),
).not.toHaveBeenWarned()
}) })
test('ATTR_ENUMERATED_COERCION', () => { test('ATTR_ENUMERATED_COERCION', () => {
@ -242,22 +231,10 @@ test('ATTR_ENUMERATED_COERCION', () => {
expect(vm.$el.getAttribute('draggable')).toBe('false') expect(vm.$el.getAttribute('draggable')).toBe('false')
expect(vm.$el.getAttribute('spellcheck')).toBe('true') expect(vm.$el.getAttribute('spellcheck')).toBe('true')
expect(vm.$el.getAttribute('contenteditable')).toBe('true') expect(vm.$el.getAttribute('contenteditable')).toBe('true')
expect(
( const message = deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION] .message as Function
.message as Function expect(message('draggable', null, 'false')).toHaveBeenWarned()
)('draggable', null, 'false'), expect(message('spellcheck', 0, 'true')).toHaveBeenWarned()
).toHaveBeenWarned() expect(message('contenteditable', 'foo', 'true')).toHaveBeenWarned()
expect(
(
deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
.message as Function
)('spellcheck', 0, 'true'),
).toHaveBeenWarned()
expect(
(
deprecationData[DeprecationTypes.ATTR_ENUMERATED_COERCION]
.message as Function
)('contenteditable', 'foo', 'true'),
).toHaveBeenWarned()
}) })

View File

@ -1,87 +0,0 @@
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 false', () => {
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()
})
})