UNPKG

2.53 kBJavaScriptView Raw
1import test from 'ava';
2import sinon from 'sinon';
3import {mount} from 'vuenit';
4import {createHOC, createHOCc, createRenderFn, createRenderFnc} from '../dist';
5
6const Component = {
7 props : ['propA', 'propB'],
8 template: `<ul>
9 <li>{{propA}}</li>
10 <li>{{propB}}</li>
11 </ul>`
12};
13
14mount(Component);
15
16test('props filter through hoc into component', t => {
17 const enhance = createHOCc({
18 });
19 const enhanced = enhance(null, Component);
20
21 const vm = mount(enhanced, {
22 props : {
23 propA : 'foo',
24 propB: 'bah',
25 }
26 });
27
28 const expected = `<ul><li>foo</li><li>bah</li></ul>`;
29
30 t.is(vm.$html, expected);
31});
32
33test('can overwrite prop values', t => {
34 const enhance = createHOCc({
35 render : createRenderFnc({
36 props : {
37 propA : 'bah',
38 propB : 'foo'
39 }
40 })
41 }, null);
42 const enhanced = enhance(Component);
43
44 const vm = mount(enhanced, {
45 props : {
46 propA : 'foo',
47 propB: 'bah',
48 }
49 });
50
51 const expected = `<ul><li>bah</li><li>foo</li></ul>`;
52
53 t.is(vm.$html, expected);
54});
55
56test('can amend prop values with a function', t => {
57 const enhance = createHOCc({
58 render: createRenderFnc({
59 props(props){
60 return {
61 propA : this.$props.propB,
62 propB : props.propA,
63 };
64 }
65 })
66 }, null);
67 const enhanced = enhance(Component);
68
69 const vm = mount(enhanced, {
70 props : {
71 propA : 'foo',
72 propB: 'bah',
73 }
74 });
75
76 const expected = `<ul><li>bah</li><li>foo</li></ul>`;
77
78 t.is(vm.$html, expected);
79});
80
81test('can add additional props', t => {
82 const enhance = createHOCc({
83 props : ['propB', 'propC'],
84 render : createRenderFnc({
85 props(props){
86 t.is(Object.hasOwnProperty.call(props, 'propA'), true);
87 t.is(Object.hasOwnProperty.call(props, 'propB'), true);
88 return {
89 propA : props.propC[0],
90 propB : props.propC[1]
91 };
92 }
93 })
94 }, null);
95 const enhanced = enhance(Component);
96
97 const vm = mount(enhanced, {
98 props : {
99 propA : 'foo',
100 propB : 'bah',
101 propC : ['abc', 'def']
102 }
103 });
104
105 const expected = `<ul><li>abc</li><li>def</li></ul>`;
106
107 t.is(vm.$html, expected);
108});
109
110test('can pass props through multiple hocs', t => {
111 const hoc1 = createHOCc({}, {}, Component);
112 const hoc2 = createHOCc({}, {}, hoc1);
113
114 const vm = mount(hoc2, {
115 props : {
116 propA : 'foo',
117 propB : 'bah',
118 }
119 });
120
121 const expected = `<ul><li>foo</li><li>bah</li></ul>`;
122
123 t.is(vm.$html, expected);
124});