Skip to content
This repository was archived by the owner on Dec 12, 2020. It is now read-only.

Commit d9e9f45

Browse files
committed
linking to root readme
1 parent 71ff421 commit d9e9f45

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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

619625
See issues labeled [v2](https://github.com/bahmutov/cypress-vue-unit-test/labels/v2)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const greeting = 'world'
163 KB
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
})

0 commit comments

Comments
 (0)