-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(TS): Cypress commands return jQuery objects (#56)
Without this fix, the types are wrong using methods like `invoke` or using callbacks on commands.
- Loading branch information
1 parent
c40e7ae
commit a375930
Showing
3 changed files
with
84 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,42 @@ | ||
describe('Foo', () => { | ||
it('has proper types', () => { | ||
cy.visit('#/foo') | ||
|
||
cy.getAllByPlaceholderText('foo').should(elements => { | ||
// argument should be an array of HTML elements | ||
expect(elements.length).to.eq(0) | ||
expect(elements[0].tagName).to.eq(0) | ||
}) | ||
|
||
// with regex | ||
cy.queryByPlaceholderText<'a'>(/foo/).should(element => { | ||
// node can be null | ||
if (element) { | ||
// argument should be an anchor | ||
expect(element.href).to.eq('') | ||
} | ||
}) | ||
|
||
// with matcher function | ||
const matcherFn = (content: string, element: HTMLElement) => true | ||
|
||
cy.queryByPlaceholderText<HTMLAudioElement>(matcherFn).should(element => { | ||
// node can be null | ||
if (element) { | ||
// argument should be an Audio element | ||
expect(element.play).to.exist | ||
} | ||
}) | ||
|
||
// with matcher options | ||
cy.queryAllByPlaceholderText<HTMLAudioElement>('foo', { | ||
collapseWhitespace: true, | ||
exact: true, | ||
timeout: 500, | ||
trim: true, | ||
}).should(elements => { | ||
const el = elements[0] | ||
// node can be null | ||
if (el) { | ||
// argument should be an array of Audio elements | ||
expect(el.play).to.exist | ||
} | ||
}) | ||
test('includes proper TypeScript types', () => { | ||
cy.visit('#/foo') | ||
|
||
cy.getAllByPlaceholderText('foo').should($elements => { | ||
expect($elements.length).to.eq(0) | ||
expect($elements[0].tagName).to.eq(0) | ||
}) | ||
|
||
// With regex | ||
cy.queryByPlaceholderText<'a'>(/foo/).should($element => { | ||
const element = $element.get(0) | ||
|
||
if (element) { | ||
expect(element.href).to.eq('') | ||
} | ||
}) | ||
|
||
// With matcher function | ||
const matcherFn = (content: string, $element: HTMLElement) => true | ||
|
||
cy.queryByPlaceholderText<HTMLAudioElement>(matcherFn).should($element => { | ||
const element = $element.get(0) | ||
|
||
if (element) { | ||
expect(element.play).to.exist | ||
} | ||
}) | ||
|
||
// With matcher options | ||
cy.queryAllByPlaceholderText<HTMLAudioElement>('foo', { | ||
collapseWhitespace: true, | ||
exact: true, | ||
timeout: 500, | ||
trim: true, | ||
}).should($elements => { | ||
const element = $elements[0] | ||
|
||
if (element) { | ||
expect(element.play).to.exist | ||
} | ||
}) | ||
}) |
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