mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2025-07-17 21:19:12 +08:00
feat: add directive feature
This commit is contained in:
@ -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,
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user