-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: Add TypeScript example. #515
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
Changes from 10 commits
7f408b1
7d49b88
05d73fa
03fabd6
42c4dd5
409b4ed
b89a685
f86936a
fc17cf2
51a2f36
9fcf0f0
321b449
ef21be5
595597a
61dd4ec
9d600c4
ba3bcef
80674f5
a42194f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Out-of-the-box TypeScript | ||
| > Write tests in TypeScript without setting up preprocessors | ||
|
|
||
| From Cypress 4.4.0, you can write tests in TypeScript without setting up preprocessors. See [the official doc](https://docs.cypress.io/guides/tooling/typescript-support.html). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>Test</title> | ||
| </head> | ||
| <body> | ||
| <a href="#">click me</a> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* global window */ | ||
| /// <reference path="../types.d.ts" /> | ||
|
|
||
| before(() => { | ||
| // @ts-expect-error | ||
| window.add = (a, b) => a + b | ||
|
||
| }) | ||
|
|
||
| describe('tests', () => { | ||
| it('test custom command', () => { | ||
| cy.visit('cypress/fixtures/test.html') | ||
| cy.clickLink('click me') | ||
sainthkh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
|
|
||
| it('test extending AUTWindow', () => { | ||
| cy.window().then((win) => { | ||
| win.add = (a, b) => a + b | ||
|
|
||
| return win.add(2, 3) | ||
| }) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /// <reference types="cypress" /> | ||
|
|
||
| export default (on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) => { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /// <reference types="cypress" /> | ||
|
|
||
| // Copied an example command from https://on.cypress.io/custom-commands | ||
| Cypress.Commands.add('clickLink', (label: string | number | RegExp) => { | ||
| cy.get('a').contains(label).click() | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // *********************************************************** | ||
| // This example support/index.js is processed and | ||
| // loaded automatically before your test files. | ||
| // | ||
| // This is a great place to put global configuration and | ||
| // behavior that modifies Cypress. | ||
| // | ||
| // You can change the location of this file or turn off | ||
| // automatically serving support files with the | ||
| // 'supportFile' configuration option. | ||
| // | ||
| // You can read more here: | ||
| // https://on.cypress.io/configuration | ||
| // *********************************************************** | ||
|
|
||
| // Import commands.js using ES2015 syntax: | ||
| import './commands' | ||
|
|
||
| // Alternatively you can use CommonJS syntax: | ||
| // require('./commands') |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // reference code is written like below to avoid the clash in mocha types. | ||
| // in most of the cases, simple <reference types="cypress" /> will do. | ||
| /// <reference path="../../../node_modules/cypress/types/cy-blob-util.d.ts" /> | ||
| /// <reference path="../../../node_modules/cypress/types/cy-bluebird.d.ts" /> | ||
| /// <reference path="../../../node_modules/cypress/types/cy-moment.d.ts" /> | ||
| /// <reference path="../../../node_modules/cypress/types/cy-minimatch.d.ts" /> | ||
| /// <reference path="../../../node_modules/cypress/types/lodash/index.d.ts" /> | ||
| /// <reference path="../../../node_modules/cypress/types/sinon/index.d.ts" /> | ||
| /// <reference path="../../../node_modules/cypress/types/jquery/index.d.ts" /> | ||
| /// <reference path="../../../node_modules/cypress/types/cypress.d.ts" /> | ||
| /// <reference path="../../../node_modules/cypress/types/cypress-type-helpers.d.ts" /> | ||
| /// <reference path="../../../node_modules/cypress/types/cypress-global-vars.d.ts" /> | ||
|
|
||
| declare namespace Cypress { | ||
| interface Chainable<Subject=any> { | ||
bahmutov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| clickLink(label: string | number | RegExp): void | ||
bahmutov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| interface ApplicationWindow { | ||
bahmutov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| add(a: number, b: number): number | ||
bahmutov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "name": "with-typescript", | ||
| "version": "1.0.0", | ||
| "description": "Use out-of-the-box TypeScript with TypeScript", | ||
| "scripts": { | ||
| "cypress:open": "../../node_modules/.bin/cypress open", | ||
| "precypress:run": "npm run lint", | ||
| "cypress:run": "../../node_modules/.bin/cypress run", | ||
| "lint": "../../node_modules/.bin/tslint --project ./tsconfig.json", | ||
| "postlint": "npm run tsc", | ||
| "test:ci": "../../node_modules/.bin/cypress run", | ||
| "test:ci:windows": "bin-up cypress run", | ||
| "tsc": "../../node_modules/.bin/tsc --pretty --noEmit" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
bahmutov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "include": [ | ||
| "cypress/integration/*.ts", | ||
| "cypress/integration/**/*.ts", | ||
| ] | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.