forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument-spec.js
37 lines (35 loc) · 1 KB
/
document-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
28
29
30
31
32
33
34
35
36
37
/// <reference types="cypress" />
import React from 'react'
import { mount } from 'cypress-react-unit-test'
// example from https://github.com/bahmutov/cypress-react-unit-test/issues/52
const DocumentTest = ({ reportHeight }) => (
<div>
<button
onClick={() =>
reportHeight(
document.documentElement.clientHeight,
document.body.clientHeight,
)
}
>
Report height
</button>
</div>
)
describe('DocumentTest', () => {
it('has valid dimensions', () => {
const reportHeight = cy.stub().as('report')
mount(<DocumentTest reportHeight={reportHeight} />)
cy.get('button').click()
cy.get('@report')
.should('have.been.called')
.its('firstCall.args')
.then(([docElementHeight, docBodyHeight]) => {
expect(docElementHeight)
.to.be.gt(0)
.and.equal(Cypress.config('viewportHeight'))
// contains a single DIV, so probably more than 10px
expect(docBodyHeight).to.be.gt(10)
})
})
})