mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2025-07-03 18:43:26 +08:00
refactor: directives
This commit is contained in:
@ -1,64 +0,0 @@
|
||||
import { shallowMount } from '@vue/test-utils';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
test('directive', () => {
|
||||
const calls = [];
|
||||
const customDirective = {
|
||||
mounted() {
|
||||
calls.push(1);
|
||||
},
|
||||
};
|
||||
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,
|
||||
});
|
||||
});
|
||||
|
||||
test('directive in spread object property', () => {
|
||||
const calls = [];
|
||||
const customDirective = {
|
||||
mounted() {
|
||||
calls.push(1);
|
||||
},
|
||||
};
|
||||
const directives = [
|
||||
{
|
||||
name: 'custom-directive',
|
||||
value: 123,
|
||||
modifiers: { modifier: true },
|
||||
arg: 'arg',
|
||||
},
|
||||
];
|
||||
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: { modifier: true },
|
||||
dir: customDirective,
|
||||
arg: 'arg',
|
||||
value: 123,
|
||||
});
|
||||
});
|
@ -145,7 +145,7 @@ test('domProps input[checked]', () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.componentVM);
|
||||
expect(wrapper.vm.$.subTree.props.checked).toBe(val);
|
||||
});
|
||||
|
||||
test('domProps option[selected]', () => {
|
||||
@ -155,7 +155,18 @@ test('domProps option[selected]', () => {
|
||||
return <option selected={val} />;
|
||||
},
|
||||
});
|
||||
expect(wrapper);
|
||||
expect(wrapper.vm.$.subTree.props.selected).toBe(val);
|
||||
});
|
||||
|
||||
test('domProps video[muted]', () => {
|
||||
const val = 'foo';
|
||||
const wrapper = shallowMount({
|
||||
render() {
|
||||
return <video muted={val} />;
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.vm.$.subTree.props.muted).toBe(val);
|
||||
});
|
||||
|
||||
test('Spread (single object expression)', () => {
|
||||
@ -190,6 +201,7 @@ test('Spread (mixed)', async () => {
|
||||
{...data}
|
||||
class={{ c: true }}
|
||||
onClick={() => calls.push(4)}
|
||||
hook-insert={() => calls.push(2)}
|
||||
/>
|
||||
);
|
||||
},
|
||||
@ -204,3 +216,29 @@ test('Spread (mixed)', async () => {
|
||||
|
||||
expect(calls).toEqual(expect.arrayContaining([3, 4]));
|
||||
});
|
||||
|
||||
test('directive', () => {
|
||||
const calls = [];
|
||||
const customDirective = {
|
||||
mounted() {
|
||||
calls.push(1);
|
||||
},
|
||||
};
|
||||
const wrapper = shallowMount(({
|
||||
directives: { custom: customDirective },
|
||||
setup() {
|
||||
return () => (
|
||||
<a
|
||||
v-custom={{
|
||||
value: 123,
|
||||
modifiers: { modifier: true },
|
||||
arg: 'arg',
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
}));
|
||||
const node = wrapper.vm.$.subTree;
|
||||
expect(calls).toEqual(expect.arrayContaining([1]));
|
||||
expect(node.dirs).toHaveLength(1);
|
||||
});
|
||||
|
Reference in New Issue
Block a user