This repository was archived by the owner on Dec 12, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +53
-1
lines changed
cypress/component/advanced/mocking-imports Expand file tree Collapse file tree 6 files changed +53
-1
lines changed Original file line number Diff line number Diff line change 1010
1111> A little helper to unit test Vue components in the open source [ Cypress.io] ( https://www.cypress.io/ ) E2E test runner ** v4.5.0+**
1212
13- ** Jump to:** [ Comparison] ( #comparison ) , Examples: [ basic] ( #basic-examples )
13+ ** Jump to:** [ Comparison] ( #comparison ) , Examples: [ basic] ( #basic-examples ) , [ advanced ] ( #advanced-examples )
1414
1515## TLDR
1616
@@ -614,6 +614,12 @@ Spec | Description
614614--- | ---
615615[ Hello] ( cypress/component/basic/hello ) | Testing examples from Vue2 cookbook
616616
617+ ### Advanced examples
618+
619+ Spec | Description
620+ --- | ---
621+ [ mocking-imports] ( cypress/component/advanced/mocking-imports ) | Stub ES6 imports from the tests
622+
617623## Known problems
618624
619625See issues labeled [ v2] ( https://github.com/bahmutov/cypress-vue-unit-test/labels/v2 )
Original file line number Diff line number Diff line change 1+ <template >
2+ <div >Hello, {{ greeting }}!</div >
3+ </template >
4+
5+ <script >
6+ import { greeting } from " ./greeting" ;
7+
8+ export default {
9+ name: " Hello" ,
10+ data () {
11+ return {
12+ greeting
13+ };
14+ }
15+ };
16+ </script >
Original file line number Diff line number Diff line change 1+ # Mocking ES6 imports
2+
3+ Vue component in [ Hello.vue] ( Hello.vue ) imports a named ES6 import from [ greeting.js] ( greeting.js ) . From the test [ spec.js] ( spec.js ) we can mock that import to make testing simpler.
4+
5+ Compare no mocking
6+
7+ ![ Test without mocking] ( images/no-mocking.png )
Original file line number Diff line number Diff line change 1+ export const greeting = 'world'
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ import Hello from './Hello.vue'
3+ import { mount } from 'cypress-vue-unit-test'
4+ import * as GreetingModule from './greeting'
5+
6+ describe ( 'Mocking ES6 imports' , ( ) => {
7+ beforeEach ( ( ) => {
8+ cy . viewport ( 300 , 200 )
9+ } )
10+
11+ it ( 'shows real greeting without mocking' , ( ) => {
12+ mount ( Hello )
13+ cy . contains ( 'Hello, world!' )
14+ } )
15+
16+ // https://github.com/bahmutov/cypress-vue-unit-test/issues/328
17+ it . skip ( 'shows mocked greeting' , ( ) => {
18+ cy . stub ( GreetingModule , 'greeting' ) . returns ( 'Cypress' )
19+ mount ( Hello )
20+ cy . contains ( 'Hello, Cypress!' )
21+ } )
22+ } )
You can’t perform that action at this time.
0 commit comments