feat: add directive feature

This commit is contained in:
252675163
2020-05-17 16:26:33 +08:00
committed by Amour1688
parent 951e973e93
commit 49a6b88edc
5 changed files with 145 additions and 39 deletions

View File

@ -1,5 +1,6 @@
import { shallowMount } from '@vue/test-utils';
import { defineComponent } from 'vue';
import { createMountedApp } from './util';
test('directive', () => {
const calls = [];
const customDirective = {
@ -7,30 +8,30 @@ test('directive', () => {
calls.push(1);
},
};
const compoentA = defineComponent(
{
directives: { customDirective },
render: () => (
<div
v-custom-directive={
{
value: 123,
modifiers: { modifier: true },
arg: 'arg',
}
} />
),
},
);
const { node } = createMountedApp(compoentA);
const compoentA = defineComponent({
directives: { custom: customDirective },
render: () => (
<a
v-custom={{
value: 123,
modifiers: { modifier: true },
arg: 'arg',
}}
/>
),
});
const wrapper = shallowMount(compoentA);
const node = wrapper.vm.$.subTree;
expect(calls).toEqual(expect.arrayContaining([1]));
expect(node.dirs).toHaveLength(1);
expect(node.dirs[0]).toMatchObject({
modifiers: { modifier: true }, dir: customDirective, arg: 'arg', value: 123,
modifiers: { modifier: true },
dir: customDirective,
arg: 'arg',
value: 123,
});
});
test('directive in spread object property', () => {
const calls = [];
const customDirective = {
@ -40,19 +41,24 @@ test('directive in spread object property', () => {
};
const directives = [
{
name: 'custom-directive', value: 123, modifiers: { modifier: true }, arg: 'arg',
name: 'custom-directive',
value: 123,
modifiers: { modifier: true },
arg: 'arg',
},
];
const compoentA = defineComponent(
{
directives: { customDirective },
render: () => (<div {...{ directives }}>123</div>),
},
);
const { node } = createMountedApp(compoentA);
const compoentA = defineComponent({
directives: { customDirective },
render: () => <a {...{ directives }}>123</a>,
});
const wrapper = shallowMount(compoentA);
const node = wrapper.vm.$.subTree;
expect(calls).toEqual(expect.arrayContaining([1]));
expect(node.dirs).toHaveLength(1);
expect(node.dirs[0]).toMatchObject({
modifiers: { abc: true }, dir: customDirective, arg: 'arg', value: 123,
modifiers: { modifier: true },
dir: customDirective,
arg: 'arg',
value: 123,
});
});