-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.spec.js
44 lines (38 loc) · 1.12 KB
/
App.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
38
39
40
41
42
43
44
import React from 'react'
import App from './App'
import {mount} from 'cypress-react-unit-test'
import ApolloClient from "apollo-boost";
describe('App', () => {
it('loads real thing', () => {
mount(<App />)
// it might take a while to load real data from remote server
cy.get('[data-cy=book]', {timeout: 20000})
.should('have.length.gte', 1)
})
beforeEach(() => {
cy.fixture('books')
.then(JSON.stringify)
.as('booksText')
})
it('can mock window fetch', function () {
cy.stub(window, 'fetch').withArgs("https://test/")
.resolves({
text: cy.stub().resolves(this.booksText).as('text')
}).as('fetch')
const client = new ApolloClient({
uri: "https://test/"
});
mount(<App apolloClient={client} />)
cy.get('[data-cy=book]').should('have.length', 2)
})
it('handles errors', () => {
cy.stub(window, 'fetch')
.withArgs("https://test/")
.rejects(new Error('Nope'))
const client = new ApolloClient({
uri: "https://test/"
});
mount(<App apolloClient={client} />)
cy.contains('Error :(').should('be.visible')
})
})