1+ /// <reference types="cypress" />
2+ 'use strict'
3+
14import AjaxList from '../../components/AjaxList.vue'
25const mountVue = require ( '../..' )
36
47/* eslint-env mocha */
58describe ( 'AjaxList' , ( ) => {
6- beforeEach ( mountVue ( AjaxList ) )
9+ // because this component loads data right away
10+ // we need to setup XHR intercepts BEFORE mounting it
11+ // thus each test will first do its "cy.route"
12+ // then will mount the component
713
814 it ( 'loads list of posts' , ( ) => {
915 // now we can observe the XHR to the server
1016 cy . get ( 'li' ) . should ( 'have.length' , 3 )
1117 } )
1218
19+
1320 it ( 'can inspect real data in XHR' , ( ) => {
1421 cy . server ( )
1522 cy . route ( '/users?_limit=3' ) . as ( 'users' )
23+ mountVue ( AjaxList ) ( )
24+
1625 cy . wait ( '@users' ) . its ( 'response.body' ) . should ( 'have.length' , 3 )
1726 } )
1827
28+
1929 it ( 'can display mock XHR response' , ( ) => {
2030 cy . server ( )
2131 const users = [ { id : 1 , name : 'foo' } ]
2232 cy . route ( 'GET' , '/users?_limit=3' , users ) . as ( 'users' )
33+ mountVue ( AjaxList ) ( )
34+
2335 cy . get ( 'li' ) . should ( 'have.length' , 1 )
2436 . first ( ) . contains ( 'foo' )
2537 } )
@@ -28,6 +40,8 @@ describe('AjaxList', () => {
2840 cy . server ( )
2941 const users = [ { id : 1 , name : 'foo' } ]
3042 cy . route ( 'GET' , '/users?_limit=3' , users ) . as ( 'users' )
43+ mountVue ( AjaxList ) ( )
44+
3145 cy . wait ( '@users' ) . its ( 'response.body' ) . should ( 'deep.equal' , users )
3246 } )
3347
@@ -40,6 +54,8 @@ describe('AjaxList', () => {
4054 response : users ,
4155 delay : 1000
4256 } ) . as ( 'users' )
57+ mountVue ( AjaxList ) ( )
58+
4359 cy . get ( 'li' ) . should ( 'have.length' , 0 )
4460 cy . wait ( '@users' )
4561 cy . get ( 'li' ) . should ( 'have.length' , 1 )
0 commit comments