babel-plugin-jsx/test/index.test.js

91 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-05-14 13:24:22 +08:00
import { shallowMount } from '@vue/test-utils';
2020-05-13 19:14:28 +08:00
test('should render with setup', () => {
2020-05-14 13:24:22 +08:00
const wrapper = shallowMount({
2020-05-13 19:14:28 +08:00
setup() {
return () => <div>123</div>;
},
2020-05-14 13:24:22 +08:00
});
expect(wrapper.text()).toBe('123');
});
test('Extracts attrs', () => {
const wrapper = shallowMount({
setup() {
return () => <div id="hi" dir="ltr" />;
},
});
expect(wrapper.element.id).toBe('hi');
expect(wrapper.element.dir).toBe('ltr');
});
2020-05-13 19:14:28 +08:00
2020-05-14 13:24:22 +08:00
test('Binds attrs', () => {
const id = 'foo';
const wrapper = shallowMount({
setup() {
return () => <div>{id}</div>;
},
});
expect(wrapper.text()).toBe('foo');
2020-05-13 19:14:28 +08:00
});
test('should not fallthrough with inheritAttrs: false', () => {
const Child = (props) => <div>{props.foo}</div>;
Child.inheritAttrs = false;
2020-05-14 13:24:22 +08:00
const wrapper = shallowMount({
setup() {
return () => (
<Child class="parent" foo={1} />
);
},
});
expect(wrapper.text()).toBe('1');
2020-05-13 19:14:28 +08:00
});
test('should render', () => {
const App = {
render() {
return <div>1234</div>;
},
};
2020-05-14 13:24:22 +08:00
const wrapper = shallowMount(App);
expect(wrapper.html()).toBe('<div>1234</div>');
2020-05-13 19:14:28 +08:00
});
test('xlink:href', () => {
2020-05-14 13:24:22 +08:00
const wrapper = shallowMount({
setup() {
return () => <use xlinkHref={'#name'}></use>;
},
});
expect(wrapper.attributes()['xlink:href']).toBe('#name');
2020-05-13 19:14:28 +08:00
});
2020-05-14 13:24:22 +08:00
// // test('Merge class', () => {
// // const wrapper = render(() => <div class="a" {...{ class: 'b' } } />);
// // expect(wrapper.innerHTML).toBe('<div class="a b"></div>');
// // });
2020-05-13 19:14:28 +08:00
test('JSXSpreadChild', () => {
const a = ['1', '2'];
2020-05-14 13:24:22 +08:00
const wrapper = shallowMount({
setup() {
return () => <div>{[...a]}</div>;
},
});
expect(wrapper.text).toBe('12');
2020-05-13 19:14:28 +08:00
});
test('domProps input[value]', () => {
const val = 'foo';
2020-05-14 13:24:22 +08:00
const wrapper = shallowMount({
setup() {
return () => <input type="text" value={val} />;
},
});
expect(wrapper.html()).toBe('<input type="text">');
2020-05-13 19:14:28 +08:00
});