Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit 2bfb833

Browse files
committed
add spec to spy on random number
1 parent e70e227 commit 2bfb833

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference types="cypress" />
2+
import React from 'react'
3+
import { mount } from 'cypress-react-unit-test'
4+
import ChildComponent from './ChildComponent'
5+
import * as calc from './calc'
6+
7+
describe('ChildComponent unstubbed', () => {
8+
it('works', () => {
9+
cy.spy(calc, 'getRandomNumber').as('getRandomNumber')
10+
mount(<ChildComponent />)
11+
// make sure the component shows the random value
12+
// returned by the calc.getRandomNumber function
13+
cy.get('@getRandomNumber')
14+
.should('have.been.called')
15+
.its('returnValues.0')
16+
.then(n => {
17+
cy.contains('.random', n)
18+
})
19+
})
20+
})

0 commit comments

Comments
 (0)