|
1 | 1 | import { Users } from '../../src/users.jsx' |
2 | 2 | import React from 'react' |
3 | | -import { mount } from '../../lib' |
4 | 3 |
|
5 | 4 | /* eslint-env mocha */ |
6 | | -describe('Users', () => { |
7 | | - beforeEach(() => { |
8 | | - mount(<Users />) |
| 5 | +context('Users', () => { |
| 6 | + describe('Component', () => { |
| 7 | + it('fetches 3 users from remote API', () => { |
| 8 | + cy.mount(<Users />) |
| 9 | + cy.get('li').should('have.length', 3) |
| 10 | + }) |
9 | 11 | }) |
10 | 12 |
|
11 | | - it('fetches 3 users from remote API', () => { |
12 | | - cy.get('li').should('have.length', 3) |
13 | | - }) |
| 13 | + describe('Network State', () => { |
| 14 | + beforeEach(() => { |
| 15 | + cy.server() |
| 16 | + // cy.mount the component after defining routes in tests |
| 17 | + // preventing race conditions where you wait on untouched routes |
| 18 | + }) |
14 | 19 |
|
15 | | - it('can inspect real data in XHR', () => { |
16 | | - cy.server() |
17 | | - cy.route('/users?_limit=3').as('users') |
18 | | - cy.wait('@users').its('response.body').should('have.length', 3) |
19 | | - }) |
20 | 20 |
|
21 | | - it('can display mock XHR response', () => { |
22 | | - cy.server() |
23 | | - const users = [{id: 1, name: 'foo'}] |
24 | | - cy.route('GET', '/users?_limit=3', users).as('users') |
25 | | - cy.get('li').should('have.length', 1) |
26 | | - .first().contains('foo') |
27 | | - }) |
| 21 | + it('can inspect real data in XHR', () => { |
| 22 | + cy.route('/users?_limit=3').as('users') |
| 23 | + cy.mount(<Users />) |
| 24 | + cy.wait('@users').its('response.body').should('have.length', 3) |
| 25 | + }) |
28 | 26 |
|
29 | | - it('can inspect mocked XHR', () => { |
30 | | - cy.server() |
31 | | - const users = [{id: 1, name: 'foo'}] |
32 | | - cy.route('GET', '/users?_limit=3', users).as('users') |
33 | | - cy.wait('@users').its('response.body').should('deep.equal', users) |
34 | | - }) |
| 27 | + it('can display mock XHR response', () => { |
| 28 | + const users = [{id: 1, name: 'foo'}] |
| 29 | + cy.route('GET', '/users?_limit=3', users).as('users') |
| 30 | + cy.mount(<Users />) |
| 31 | + cy.get('li').should('have.length', 1) |
| 32 | + .first().contains('foo') |
| 33 | + }) |
| 34 | + |
| 35 | + it('can inspect mocked XHR', () => { |
| 36 | + const users = [{id: 1, name: 'foo'}] |
| 37 | + cy.route('GET', '/users?_limit=3', users).as('users') |
| 38 | + cy.mount(<Users />) |
| 39 | + cy.wait('@users').its('response.body').should('deep.equal', users) |
| 40 | + }) |
35 | 41 |
|
36 | | - it('can delay and wait on XHR', () => { |
37 | | - cy.server() |
38 | | - const users = [{id: 1, name: 'foo'}] |
39 | | - cy.route({ |
40 | | - method: 'GET', |
41 | | - url: '/users?_limit=3', |
42 | | - response: users, |
43 | | - delay: 1000 |
44 | | - }).as('users') |
45 | | - cy.get('li').should('have.length', 0) |
46 | | - cy.wait('@users') |
47 | | - cy.get('li').should('have.length', 1) |
| 42 | + it('can delay and wait on XHR', () => { |
| 43 | + const users = [{id: 1, name: 'foo'}] |
| 44 | + cy.route({ |
| 45 | + method: 'GET', |
| 46 | + url: '/users?_limit=3', |
| 47 | + response: users, |
| 48 | + delay: 1000 |
| 49 | + }).as('users') |
| 50 | + cy.mount(<Users />) |
| 51 | + cy.get('li').should('have.length', 0) |
| 52 | + cy.wait('@users') |
| 53 | + cy.get('li').should('have.length', 1) |
| 54 | + }) |
48 | 55 | }) |
49 | 56 | }) |
0 commit comments