-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(TS): fix types and add tests for types (#21)
<!-- Thanks for your interest in the project. Bugs filed and PRs submitted are appreciated! Please make sure that you are familiar with and follow the Code of Conduct for this project (found in the CODE_OF_CONDUCT.md file). Also, please make sure you're familiar with and follow the instructions in the contributing guidelines (found in the CONTRIBUTING.md file). If you're new to contributing to open source projects, you might find this free video course helpful: http://kcd.im/pull-request Please fill out the information below to expedite the review and (hopefully) merge of your pull request! --> <!-- What changes are being made? (What feature/bug is being fixed here?) --> **What**: - fixed TypeScript types - added jsdoc for helpers - added tests for types <!-- Why are these changes necessary? --> **Why**: types were not working reported here #18 (comment) by @aaronmcadam and @freddydumont <!-- How were these changes implemented? --> **How**: - added and fixed types for the helpers into Cypress namespace using global declaration as described in TS docs https://www.typescriptlang.org/docs/handbook/declaration-files/templates/global-modifying-module-d-ts.html - for testing - added `tsc --noemit` on sample ts project <!-- Have you done all of these things? --> **Checklist**: <!-- add "N/A" to the end of each line that's irrelevant to your changes --> <!-- to check an item, place an "x" in the box like so: "- [x] Documentation" --> * [x] Documentation * [x] Tests * [x] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? --> * [x] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions --> <!-- feel free to add additional comments --> This is how types being picked up by VS-Code: ![image](https://user-images.githubusercontent.com/4506749/47946634-840d6d80-decb-11e8-9be7-62fb2a68526e.png) ![image](https://user-images.githubusercontent.com/4506749/47946573-9e931700-deca-11e8-94e0-4fd6bd70ce4c.png)
- Loading branch information
Airat Aminev
authored and
Kent C. Dodds
committed
Nov 6, 2018
1 parent
d530690
commit d782f03
Showing
6 changed files
with
801 additions
and
31 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
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,45 @@ | ||
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, | ||
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 | ||
} | ||
}) | ||
}) | ||
}) |
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,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["dom", "es2015", "es2016", "es2017"], | ||
"target": "es2017", | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"experimentalDecorators": true, | ||
"outDir": "dist", | ||
"noUnusedLocals": true, | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"types": ["cypress", "../../typings"] | ||
} | ||
} |
Oops, something went wrong.