forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec.js
27 lines (23 loc) · 885 Bytes
/
spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/// <reference types="cypress" />
import React from 'react'
import { mount } from 'cypress-react-unit-test'
import Component from './component'
import * as GreetingModule from './greeting'
it('shows real greeting', () => {
mount(<Component />)
cy.contains('h1', 'real greeting').should('be.visible')
})
it('shows mock greeting', () => {
// stubbing ES6 named imports works via
// @babel/plugin-transform-modules-commonjs with "loose: true"
// because the generated properties are configurable
// stub property on the loaded ES6 module using cy.stub
// which will be restored after the test automatically
cy.stub(GreetingModule, 'greeting', 'test greeting')
mount(<Component />)
cy.contains('h1', 'test greeting').should('be.visible')
})
it('shows real greeting again', () => {
mount(<Component />)
cy.contains('h1', 'real greeting').should('be.visible')
})