forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add keystrokeDelay (cypress-io#15683)
* Add keystrokeDelay * Config tests * Add proper comments * Add some tests for configuring timeout * Add tests for false values * Few additional tests * Rename test * feat: add Cypress.Keyboard.defaults() for specifying default keystrokeDelay * use test-configuration on link * remove obsolete error message * fix types and add type tests * fix types tests * fix type test Co-authored-by: Chris Breiding <chrisbreiding@gmail.com>
- Loading branch information
Showing
7 changed files
with
334 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
packages/driver/cypress/integration/cypress/keyboard_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const { Keyboard } = Cypress | ||
|
||
const DEFAULTS = { | ||
keystrokeDelay: 10, | ||
} | ||
|
||
describe('src/cypress/keyboard', () => { | ||
beforeEach(() => { | ||
Keyboard.reset() | ||
}) | ||
|
||
it('has defaults', () => { | ||
expect(Keyboard.getConfig()).to.deep.eq(DEFAULTS) | ||
}) | ||
|
||
context('.getConfig', () => { | ||
it('returns config', () => { | ||
expect(Keyboard.getConfig()).to.deep.eq(DEFAULTS) | ||
}) | ||
|
||
it('does not allow mutation of config', () => { | ||
const config = Keyboard.getConfig() | ||
|
||
config.keystrokeDelay = 0 | ||
|
||
expect(Keyboard.getConfig().keystrokeDelay).to.eq(DEFAULTS.keystrokeDelay) | ||
}) | ||
}) | ||
|
||
context('.defaults', () => { | ||
it('is noop if not called with any valid properties', () => { | ||
Keyboard.defaults({}) | ||
expect(Keyboard.getConfig()).to.deep.eq(DEFAULTS) | ||
}) | ||
|
||
it('sets keystrokeDelay if specified', () => { | ||
Keyboard.defaults({ | ||
keystrokeDelay: 5, | ||
}) | ||
|
||
expect(Keyboard.getConfig().keystrokeDelay).to.eql(5) | ||
}) | ||
|
||
it('returns new config', () => { | ||
const result = Keyboard.defaults({ | ||
keystrokeDelay: 5, | ||
}) | ||
|
||
expect(result).to.deep.eql({ | ||
keystrokeDelay: 5, | ||
}) | ||
}) | ||
|
||
it('does not allow mutation via returned config', () => { | ||
const result = Keyboard.defaults({ | ||
keystrokeDelay: 5, | ||
}) | ||
|
||
result.keystrokeDelay = 0 | ||
|
||
expect(Keyboard.getConfig().keystrokeDelay).to.eq(5) | ||
}) | ||
|
||
describe('errors', () => { | ||
it('throws if not passed an object', () => { | ||
const fn = () => { | ||
Keyboard.defaults() | ||
} | ||
|
||
expect(fn).to.throw() | ||
.with.property('message') | ||
.and.eq('`Cypress.Keyboard.defaults()` must be called with an object. You passed: ``') | ||
|
||
expect(fn).to.throw() | ||
.with.property('docsUrl') | ||
.and.eq('https://on.cypress.io/keyboard-api') | ||
}) | ||
|
||
it('throws if keystrokeDelay is not a number', () => { | ||
const fn = () => { | ||
Keyboard.defaults({ keystrokeDelay: false }) | ||
} | ||
|
||
expect(fn).to.throw() | ||
.with.property('message') | ||
.and.eq('`Cypress.Keyboard.defaults()` `keystrokeDelay` option must be 0 (zero) or a positive number. You passed: `false`') | ||
|
||
expect(fn).to.throw() | ||
.with.property('docsUrl') | ||
.and.eq('https://on.cypress.io/keyboard-api') | ||
}) | ||
|
||
it('throws if keystrokeDelay is a negative number', () => { | ||
const fn = () => { | ||
Keyboard.defaults({ keystrokeDelay: -10 }) | ||
} | ||
|
||
expect(fn).to.throw() | ||
.with.property('message') | ||
.and.eq('`Cypress.Keyboard.defaults()` `keystrokeDelay` option must be 0 (zero) or a positive number. You passed: `-10`') | ||
|
||
expect(fn).to.throw() | ||
.with.property('docsUrl') | ||
.and.eq('https://on.cypress.io/keyboard-api') | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.