1 | import test from 'ava';
|
2 | import sinon from 'sinon';
|
3 | import {mount} from 'vuenit';
|
4 | import {createHOC, createHOCc, createRenderFn} from '../dist';
|
5 |
|
6 | const Component = {
|
7 | props : ['propA'],
|
8 | template : '<div>{{propA}}</div>',
|
9 | };
|
10 | mount(Component);
|
11 |
|
12 | test('wraps a component in a hoc', t => {
|
13 | const hoc = createHOC(Component);
|
14 | const vm = mount(hoc, {
|
15 | props: {
|
16 | propA: 'foo'
|
17 | }
|
18 | });
|
19 |
|
20 | t.true(vm.$html.includes('foo'));
|
21 | });
|
22 |
|
23 | test('wraps a component in a curried hoc', t => {
|
24 | const hoc = createHOCc(null)(null)(Component);
|
25 | const vm = mount(hoc, {
|
26 | props: {
|
27 | propA: 'foo'
|
28 | }
|
29 | });
|
30 |
|
31 | t.true(vm.$html.includes('foo'));
|
32 | });
|
33 |
|
34 | test('has a default name', t => {
|
35 | const hoc = createHOC(Component);
|
36 | const vm = mount(hoc, {
|
37 | props: {
|
38 | propA: 'foo'
|
39 | }
|
40 | });
|
41 |
|
42 | t.is(vm.$name, 'AnonymousHOC');
|
43 | });
|
44 |
|
45 | test('extends the compnent name', t => {
|
46 | const hoc = createHOC(Object.assign({name:'MyComponent'}, Component));
|
47 | const vm = mount(hoc, {
|
48 | name: 'MyComponent',
|
49 | props: {
|
50 | propA: 'foo'
|
51 | }
|
52 | });
|
53 |
|
54 | t.is(vm.$name, 'MyComponentHOC');
|
55 | });
|
56 |
|
57 | test('extends the compnent name', t => {
|
58 | const hoc = createHOC(Component, {
|
59 | name: 'MyHoc',
|
60 | });
|
61 | const vm = mount(hoc, {
|
62 | name: 'MyComponent',
|
63 | props: {
|
64 | propA: 'foo'
|
65 | }
|
66 | });
|
67 |
|
68 | t.is(vm.$name, 'MyHoc');
|
69 | });
|
70 |
|
71 | test('provide props to the hoc', t => {
|
72 | const hoc = createHOC(Component, null, {
|
73 | props: {
|
74 | propA: 'from hoc'
|
75 | }
|
76 | });
|
77 | const vm = mount(hoc, {
|
78 | props: {
|
79 | propA: 'foo'
|
80 | }
|
81 | });
|
82 |
|
83 | t.true(vm.$html.includes('from hoc'));
|
84 | t.false(vm.$html.includes('foo'));
|
85 | });
|