File tree 3 files changed +60
-3
lines changed
3 files changed +60
-3
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,17 @@ const options = {
56
56
beforeEach (mountVue (/* my Vue code */ , options))
57
57
```
58
58
59
+ * ` base ` - specify ` <base href=...> ` path. Useful to get static assets work,
60
+ but might prevent relative HTTP references from working (like path to Vue.js
61
+ from ` ../../node_modules/vue/dist/vue.js ` for example)
62
+
63
+ ``` js
64
+ const options = {
65
+ base: ' /'
66
+ }
67
+ beforeEach (mountVue (/* my Vue code */ , options))
68
+ ```
69
+
59
70
* ` html ` - custom test HTML to inject instead of default one. Good
60
71
place to load additional libraries, polyfills and styles.
61
72
@@ -466,6 +477,11 @@ describe('Hello.vue', () => {
466
477
})
467
478
```
468
479
480
+ ## FAQ
481
+
482
+ - If your component's static assets are not loading, you probably need
483
+ to start and proxy Webpack dev server. See [ issue #4 ] ( https://github.com/bahmutov/cypress-vue-unit-test/issues/4 )
484
+
469
485
## Related info
470
486
471
487
- [ Testing Vue web applications with Vuex data store & REST backend] ( https://www.cypress.io/blog/2017/11/28/testing-vue-web-application-with-vuex-data-store-and-rest-backend/ )
Original file line number Diff line number Diff line change @@ -45,3 +45,21 @@ describe('Pass window HTML to use', () => {
45
45
cy . window ( ) . its ( 'Vue.version' ) . should ( 'be.a' , 'string' )
46
46
} )
47
47
} )
48
+
49
+ describe ( 'Pass Vue.js url and base tag' , ( ) => {
50
+ const options = {
51
+ vue : 'https://unpkg.com/vue' ,
52
+ base : '/'
53
+ }
54
+
55
+ const component = { template, data }
56
+ beforeEach ( mountVue ( component , options ) )
57
+
58
+ it ( 'shows hello' , ( ) => {
59
+ cy . contains ( 'Hello Vue!' )
60
+ } )
61
+
62
+ it ( 'has version' , ( ) => {
63
+ cy . window ( ) . its ( 'Vue.version' ) . should ( 'be.a' , 'string' )
64
+ } )
65
+ } )
Original file line number Diff line number Diff line change @@ -53,11 +53,34 @@ const getPageHTML = options => {
53
53
54
54
// note: add "base" tag to force loading static assets
55
55
// from the server, not from the "spec" file URL
56
+ if ( options . base ) {
57
+ if ( vue . startsWith ( '.' ) ) {
58
+ console . error (
59
+ 'You are using base tag %s and relative Vue path %s' ,
60
+ options . base ,
61
+ vue
62
+ )
63
+ console . error ( 'the relative path might NOT work' )
64
+ console . error (
65
+ 'maybe pass Vue url using "https://unpkg.com/vue/dist/vue.js"'
66
+ )
67
+ }
68
+ return stripIndent `
69
+ <html>
70
+ <head>
71
+ <base href="${ options . base } " />
72
+ </head>
73
+ <body>
74
+ <div id="app"></div>
75
+ <script src="${ vue } "></script>
76
+ </body>
77
+ </html>
78
+ `
79
+ }
80
+
56
81
const vueHtml = stripIndent `
57
82
<html>
58
- <head>
59
- <base href="/" />
60
- </head>
83
+ <head></head>
61
84
<body>
62
85
<div id="app"></div>
63
86
<script src="${ vue } "></script>
You can’t perform that action at this time.
0 commit comments