From c0bcd5ad2c261f832b9f147d251ac783b1ac8a61 Mon Sep 17 00:00:00 2001 From: cuixiaorui Date: Sun, 12 Jul 2020 23:32:00 +0800 Subject: [PATCH 1/2] refactor: extract the repeated logic on classes.spec.ts --- tests/classes.spec.ts | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/tests/classes.spec.ts b/tests/classes.spec.ts index da7ca9d61..726dc21a3 100644 --- a/tests/classes.spec.ts +++ b/tests/classes.spec.ts @@ -4,54 +4,43 @@ import { mount } from '../src' describe('classes', () => { describe('DOMWrapper', () => { - it('returns array of class names if wrapper has class names', () => { + let wrapper + beforeEach(() => { const Component = defineComponent({ render() { return h('div', {}, [h('span', { class: 'class-a' })]) } }) - const wrapper = mount(Component) - + wrapper = mount(Component) + }) + it('returns array of class names if wrapper has class names', () => { expect(wrapper.find('.class-a').classes()).toContain('class-a') }) it('returns true if the component has the class', () => { - const Component = defineComponent({ - render() { - return h('div', {}, [h('span', { class: 'class-a' })]) - } - }) - - const wrapper = mount(Component).find('span') - - expect(wrapper.classes('class-a')).toBe(true) - expect(wrapper.classes('class-b')).toBe(false) + expect(wrapper.find('span').classes('class-a')).toBe(true) + expect(wrapper.find('span').classes('class-b')).toBe(false) }) }) describe('VueWrapper', () => { - it('returns array of class names if wrapper has class names', () => { + let wrapper + beforeEach(() => { const Component = defineComponent({ render() { return h('div', { class: 'class-a' }, 'some text') } }) - const wrapper = mount(Component) + wrapper = mount(Component) + }) + it('returns array of class names if wrapper has class names', () => { expect(wrapper.classes()).toContain('class-a') }) it('returns true if the component has the class', () => { - const Component = defineComponent({ - render() { - return h('div', { class: 'class-a' }, 'some text') - } - }) - - const wrapper = mount(Component) - expect(wrapper.classes('class-a')).toBe(true) expect(wrapper.classes('class-b')).toBe(false) }) From db5f580099bacf48be2f7ebf453b57e6b1e30644 Mon Sep 17 00:00:00 2001 From: cuixiaorui Date: Mon, 13 Jul 2020 19:17:44 +0800 Subject: [PATCH 2/2] chore: remove ShapeFlags --- src/utils/vueShared.ts | 14 -------------- src/vue-wrapper.ts | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/utils/vueShared.ts b/src/utils/vueShared.ts index 25d7ac8cf..2214494b5 100644 --- a/src/utils/vueShared.ts +++ b/src/utils/vueShared.ts @@ -19,17 +19,3 @@ const hyphenateRE = /\B([A-Z])/g export const hyphenate = cacheStringFunction((str: string): string => { return str.replace(hyphenateRE, '-$1').toLowerCase() }) - -export const enum ShapeFlags { - ELEMENT = 1, - FUNCTIONAL_COMPONENT = 1 << 1, - STATEFUL_COMPONENT = 1 << 2, - TEXT_CHILDREN = 1 << 3, - ARRAY_CHILDREN = 1 << 4, - SLOTS_CHILDREN = 1 << 5, - TELEPORT = 1 << 6, - SUSPENSE = 1 << 7, - COMPONENT_SHOULD_KEEP_ALIVE = 1 << 8, - COMPONENT_KEPT_ALIVE = 1 << 9, - COMPONENT = ShapeFlags.STATEFUL_COMPONENT | ShapeFlags.FUNCTIONAL_COMPONENT -} diff --git a/src/vue-wrapper.ts b/src/vue-wrapper.ts index 9aa6fa715..305d5d552 100644 --- a/src/vue-wrapper.ts +++ b/src/vue-wrapper.ts @@ -1,5 +1,5 @@ import { ComponentPublicInstance, nextTick, App } from 'vue' -import { ShapeFlags } from './utils/vueShared' +import { ShapeFlags } from '@vue/shared' import { config } from './config' import { DOMWrapper } from './dom-wrapper'