-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.js
70 lines (58 loc) · 1.9 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* eslint-env mocha */
/* global cy, File, Cypress */
const attachFiles = require('../..')
describe('multipart/form-data', () => {
beforeEach(() => {
cy.visit('localhost:3000')
})
it('upload', () => {
// we can enter info into the form fields
cy.get('input[name="userid"]').type('[email protected]')
// files to upload for each input[type="file"] name
// we are going to construct a single text file
const files = {
fileToUpload: new File(['foo bar'], 'test-file.txt', {
type: 'text/plain'
})
}
// get the form element and attach files to upload
cy.get('form').then(attachFiles(files))
// submit the form
cy.get('input[type="submit"]').click()
// check saved file
cy.readFile('uploads/test-file.txt').should('equal', 'foo bar')
// check current url
cy.url().should('match', /upload$/)
// check new page contents
cy.contains('Uploaded test-file.txt')
cy.contains('for [email protected]')
})
if (Cypress.platform === 'linux') {
it('upload with spying fails to spy on Travis')
} else {
it('upload with spying', () => {
// spy on XHR calls
cy.server()
cy.route('POST', '/upload').as('upload')
// we can enter info into the form fields
cy.get('input[name="userid"]').type('[email protected]')
// files to upload for each input[type="file"] name
// we are going to construct a single text file
const files = {
fileToUpload: new File(['foo bar'], 'test-file.txt', {
type: 'text/plain'
})
}
// get the form element and attach files to upload
cy.get('form').then(attachFiles(files))
// submit the form
cy.get('input[type="submit"]').click()
// check upload response
cy
.get('@upload')
.its('response.body')
.should('include', 'Uploaded test-file.txt')
.and('include', 'for [email protected]')
})
}
})