mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-22 06:59:30 -06:00
feat: add cy.mount() runner error (#19145)
* add cy.mount error if called before overriding * added index ref & cleanup * added mount spec * feat: Allow Cypress.Commands.add on hover & mount (#19633) * add clarifying comments about special commands Co-authored-by: Tim Griesser <tgriesser10@gmail.com>
This commit is contained in:
@@ -97,6 +97,24 @@ describe('src/cy/commands/commands', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('allows calling .add with hover / mount', () => {
|
||||
let calls = 0
|
||||
|
||||
Cypress.Commands.add('hover', () => {
|
||||
calls++
|
||||
})
|
||||
|
||||
Cypress.Commands.add('mount', () => {
|
||||
calls++
|
||||
})
|
||||
|
||||
cy.mount()
|
||||
cy.hover()
|
||||
cy.then(() => {
|
||||
expect(calls).to.eq(2)
|
||||
})
|
||||
})
|
||||
|
||||
it('throws when attempting to add a command with the same name as an internal function', (done) => {
|
||||
cy.on('fail', (err) => {
|
||||
expect(err.message).to.eq('`Cypress.Commands.add()` cannot create a new command named `addChainer` because that name is reserved internally by Cypress.')
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
const { $ } = Cypress
|
||||
|
||||
describe('src/cy/commands/actions/mount', () => {
|
||||
before(() => {
|
||||
cy
|
||||
.visit('/fixtures/dom.html')
|
||||
.then(function (win) {
|
||||
this.body = win.document.body.outerHTML
|
||||
})
|
||||
})
|
||||
|
||||
beforeEach(function () {
|
||||
const doc = cy.state('document')
|
||||
|
||||
$(doc.body).empty().html(this.body)
|
||||
})
|
||||
|
||||
context('#mount', () => {
|
||||
it('throws when invoking', (done) => {
|
||||
cy.on('fail', (err) => {
|
||||
expect(err.message).to.include('`cy.mount()`')
|
||||
expect(err.docsUrl).to.eq('https://on.cypress.io/mount')
|
||||
|
||||
done()
|
||||
})
|
||||
|
||||
cy.mount()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -8,6 +8,7 @@ import * as SelectFile from './selectFile'
|
||||
import * as Submit from './submit'
|
||||
import * as Type from './type'
|
||||
import * as Trigger from './trigger'
|
||||
import * as Mount from './mount'
|
||||
|
||||
export {
|
||||
Check,
|
||||
@@ -20,4 +21,5 @@ export {
|
||||
Submit,
|
||||
Type,
|
||||
Trigger,
|
||||
Mount,
|
||||
}
|
||||
|
||||
9
packages/driver/src/cy/commands/actions/mount.ts
Normal file
9
packages/driver/src/cy/commands/actions/mount.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import $errUtils from '../../../cypress/error_utils'
|
||||
|
||||
export default (Commands) => {
|
||||
return Commands.addAll({
|
||||
mount () {
|
||||
return $errUtils.throwErrByPath('mount.not_implemented')
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import $stackUtils from './stack_utils'
|
||||
import { allCommands } from '../cy/commands'
|
||||
import { addCommand } from '../cy/net-stubbing'
|
||||
|
||||
const PLACEHOLDER_COMMANDS = ['mount', 'hover']
|
||||
|
||||
const builtInCommands = [
|
||||
..._.toArray(allCommands).map((c) => c.default || c),
|
||||
addCommand,
|
||||
@@ -229,7 +231,9 @@ export default {
|
||||
})
|
||||
}
|
||||
|
||||
if (addingBuiltIns) {
|
||||
// .hover & .mount are special case commands. allow as builtins so users
|
||||
// may add them without throwing an error
|
||||
if (addingBuiltIns && !PLACEHOLDER_COMMANDS.includes(name)) {
|
||||
builtInCommandNames[name] = true
|
||||
}
|
||||
|
||||
|
||||
@@ -953,6 +953,16 @@ export default {
|
||||
|
||||
},
|
||||
|
||||
mount: {
|
||||
not_implemented: {
|
||||
message: [
|
||||
`${cmd('mount')} must be implemented by the user. There are`,
|
||||
'full instructions for doing so at the following location.',
|
||||
].join('\n'),
|
||||
docsUrl: 'https://on.cypress.io/mount',
|
||||
},
|
||||
},
|
||||
|
||||
navigation: {
|
||||
cross_origin ({ message, originPolicy, configFile, projectRoot }) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user