-
Notifications
You must be signed in to change notification settings - Fork 2
/
diff.cy.js
35 lines (30 loc) · 1.05 KB
/
diff.cy.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
/// <reference types="cypress" />
// @ts-check
import '../../commands'
// this spec shows the difference between
// cy.invoke, cy.mapInvoke, and cy.map
it('invokes a method on the subject', () => {
const list = ['apples', 'plums', 'bananas']
cy.wrap(list)
// calls ".sort()" on the list
.invoke('sort')
.should('deep.equal', ['apples', 'bananas', 'plums'])
})
it('invokes a method on the items in the subject', () => {
const list = ['apples', 'plums', 'bananas']
cy.wrap(list)
// calls ".toUpperCase()" on every string in the list
.mapInvoke('toUpperCase')
.should('deep.equal', ['APPLES', 'PLUMS', 'BANANAS'])
})
it('maps each item by running it through the callback or property', () => {
const list = ['apples', 'plums', 'bananas']
const reverse = (s) => s.split('').reverse().join('')
cy.wrap(list)
// reverses each string in the list
.map(reverse)
.should('deep.equal', ['selppa', 'smulp', 'sananab'])
// grabs the "length" property from each string
.map('length')
.should('deep.equal', [6, 5, 7])
})