-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathadd-commands.js
47 lines (42 loc) · 1.71 KB
/
add-commands.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
import {commands} from '../'
test('adds commands to Cypress', () => {
const addMock = jest.fn().mockName('Cypress.Commands.add')
const addQueryMock = jest.fn().mockName('Cypress.Commands.addQuery')
const overwriteQueryMock = jest
.fn()
.mockName('Cypress.Commands.overwriteQuery')
global.Cypress = {
Commands: {
add: addMock,
addQuery: addQueryMock,
overwriteQuery: overwriteQueryMock,
},
}
global.cy = {
findAllByLabelText: jest.fn(),
}
require('../add-commands')
/** Commands that we're adding to the cy. namespace */
const newCommands = commands.filter(({name}) => !global.cy[name])
/** Commands that we're overwriting in the cy. namespace */
const overwrittenCommands = commands.filter(({name}) => global.cy[name])
expect(addQueryMock).toHaveBeenCalledTimes(newCommands.length)
expect(overwriteQueryMock).toHaveBeenCalledTimes(overwrittenCommands.length)
expect(addMock).toHaveBeenCalledTimes(1) // we're also adding a configuration command
newCommands.forEach(({name}, index) => {
expect(addQueryMock.mock.calls[index]).toMatchObject([
name,
// We get a new function that is `command.bind(null, cy)` i.e. global `cy` passed into the first argument.
// The commands themselves will be tested separately in the Cypress end-to-end tests.
expect.any(Function),
])
})
overwrittenCommands.forEach(({name}, index) => {
expect(overwriteQueryMock.mock.calls[index]).toMatchObject([
name,
// We get a new function that is `command.bind(null, cy)` i.e. global `cy` passed into the first argument.
// The commands themselves will be tested separately in the Cypress end-to-end tests.
expect.any(Function),
])
})
})