Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .clear support for HTML 5 input types #2793

Merged
merged 7 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions packages/driver/src/cy/commands/actions/type.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,22 @@ module.exports = (Commands, Cypress, cy, state, config) ->
args: { word, node }
}

cy.now("type", $el, "{selectall}{del}", {
$el: $el
log: false
verify: false ## handle verification ourselves
_log: options._log
force: options.force
timeout: options.timeout
interval: options.interval
}).then ->
if ["date", "month", "time", "week"].includes($el.attr("type"))
lilaconlee marked this conversation as resolved.
Show resolved Hide resolved
$el.val("")
options._log.snapshot().end() if options._log

return null
else
cy.now("type", $el, "{selectall}{del}", {
$el: $el
log: false
verify: false ## handle verification ourselves
_log: options._log
force: options.force
timeout: options.timeout
interval: options.interval
}).then ->
options._log.snapshot().end() if options._log

return null

Promise
.resolve(subject.toArray())
Expand Down
1 change: 1 addition & 0 deletions packages/driver/test/cypress/fixtures/dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
<input id="time-with-value" type="time" value="01:23:45" />
<input id="time-without-value" type="time" />

<input id="tel-with-value" type="tel" value="678-999-8212" />
<div contenteditable="true"></div>
<textarea></textarea>
<input id="bad-type" type="asdf" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2891,7 +2891,7 @@ describe "src/cy/commands/actions/type", ->

context "[type=tel]", ->
it "can edit tel", ->
cy.get('input[type="tel"]')
cy.get('#by-name > input[type="tel"]')
.type('1234567890')
.should('have.prop', 'value', '1234567890')

Expand Down Expand Up @@ -3037,9 +3037,21 @@ describe "src/cy/commands/actions/type", ->

cy.get("#input-covered-in-span").clear({timeout: 1000, interval: 60})

it "works on input[type=number]", ->
cy.get("#number-with-value").clear().then ($input) ->
expect($input.val()).to.equal("")
context "works on input type", ->
inputTypes = [
chrisbreiding marked this conversation as resolved.
Show resolved Hide resolved
"date",
"email",
"month",
"number",
"tel",
"time",
"week"
]

inputTypes.forEach (type) ->
it type, ->
cy.get("##{type}-with-value").clear().then ($input) ->
expect($input.val()).to.equal("")

describe "assertion verification", ->
beforeEach ->
Expand Down