@@ -23,6 +23,7 @@ import { mapState } from "vuex";
23
23
const { fs , ipcRenderer } = window ;
24
24
25
25
import writeNested from " ../../mixins/writeNested" ;
26
+ import { result } from " lodash" ;
26
27
27
28
28
29
export default {
@@ -104,7 +105,33 @@ export default {
104
105
* @description : creates component code <template>, <script>, <style>
105
106
* invokes writeTemplate, writeScript, writeStyle
106
107
*/
107
- createComponentCode (componentLocation , componentName , children , routes ) {
108
+
109
+ writeRenderUnitTestString (componentName , htmlList ) {
110
+
111
+ const imports = ` import { mount } from '@vue/test-utils'
112
+ import ${ componentName} from '../src/components/${ componentName} .vue'`
113
+ const results = [imports];
114
+
115
+ for (const el of htmlList) {
116
+ const test = `
117
+ test('renders ${ componentName} ', () => {
118
+ const wrapper = mount(${ componentName} )
119
+
120
+ const ele = wrapper.get('[data-test="${ componentName} -${ el .text } -${ el .id } "]')
121
+
122
+ expect(ele.exists()).toBe(true)
123
+ })`
124
+ results .push (test);
125
+ }
126
+
127
+ return results .reduce ((acc , ele ) => acc += ele, ' ' );
128
+ },
129
+
130
+ createComponentTestCode (componentLocation , componentName , componentMap ) {
131
+ fs .writeFileSync (componentLocation, this .writeRenderUnitTestString (componentName, componentMap[componentName].htmlList ))
132
+ },
133
+
134
+ createComponentCode (componentLocation , componentName , children ) {
108
135
if (componentName === " App" ) {
109
136
fs .writeFileSync (
110
137
componentLocation + " .vue" ,
@@ -205,12 +232,13 @@ export default {
205
232
let htmlArr = this .componentMap [componentName].htmlList ;
206
233
let outputStr = ` ` ;
207
234
// eslint-disable-next-line no-unused-vars
208
- for (let el of htmlArr) {
235
+ for (let i = 0 ; i < htmlArr .length ; i++ ) {
236
+ const el = htmlArr[i];
209
237
if (! el .text ) {
210
- outputStr += ` <${ el} />\n ` ;
238
+ outputStr += ` <${ el} [data-test= ${ componentName } - ${ el } - ${ i } ] />\n ` ;
211
239
} else {
212
240
outputStr += ` ` ;
213
- outputStr += htmlElementMap[el .text ][0 ]
241
+ outputStr += htmlElementMap[el .text ][0 ] + ` [data-test= ${ componentName } - ${ el . text } - ${ el . id } ] `
214
242
// if conditional to check class
215
243
if (el .class !== " " ) {
216
244
outputStr += " " + " class = " + ` "${ el .class } "` ;
@@ -806,6 +834,8 @@ export default {
806
834
fs .mkdirSync (path .join (data, " src" , " views" ));
807
835
fs .mkdirSync (path .join (data, " src" , " router" ));
808
836
fs .mkdirSync (path .join (data, " src" , " store" ));
837
+ fs .mkdirSync (path .join (data, " test" ));
838
+ fs .mkdirSync (path .join (data, " test" , " components" ));
809
839
}
810
840
// creating basic boilerplate for vue app
811
841
this .createIndexFile (data);
@@ -848,6 +878,9 @@ export default {
848
878
componentName,
849
879
this .componentMap
850
880
);
881
+ this .createComponentTestCode (path .join (data, " test" , " components" , componentName + ' .test.js' ),
882
+ componentName,
883
+ this .componentMap )
851
884
}
852
885
// if componentName is App
853
886
} else {
0 commit comments