From 7a2c21144fc66e080eb4f0c71ac4fb81ea5facfa Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Fri, 13 Jul 2018 00:42:50 +0200 Subject: [PATCH] add missing TypeScript jsdocs for types for issue 2009 (#2137) * doc second cy.find type * document type for cy.request * document Cypress.env command * doc type for Cypress.log * doc types for uncheck * add type docs for cy.spy * document spies and stubs types * add space to align jsdoc stars * types: show to correctly pass request options, close #2093 * cast just the http method property * types for spy withArgs and as * doc more types for overrides * type for spread * type for overriden then * types for cy.trigger overrides * rest of types of overriden methods, close #2009 --- cli/types/index.d.ts | 360 +++++++++++++++++++++++++++++++- cli/types/tests/kitchen-sink.ts | 30 +++ 2 files changed, 380 insertions(+), 10 deletions(-) diff --git a/cli/types/index.d.ts b/cli/types/index.d.ts index 5072203381..6c4d26393f 100644 --- a/cli/types/index.d.ts +++ b/cli/types/index.d.ts @@ -163,13 +163,41 @@ declare namespace Cypress { // no real way to type without generics /** + * Returns all environment variables set with CYPRESS_ prefix or in "env" object in "cypress.json" + * * @see https://on.cypress.io/env */ env(): ObjectLike + /** + * Returns specific environment variable or undefined + * @see https://on.cypress.io/env + * @example + * // cypress.json + * { "env": { "foo": "bar" } } + * Cypress.env("foo") // => bar + */ env(key: string): any + /** + * Set value for a variable. + * Any value you change will be permanently changed for the remainder of your tests. + * @see https://on.cypress.io/env + * @example + * Cypress.env("host", "http://server.dev.local") + */ env(key: string, value: any): void + /** + * Set values for multiple variables at once. Values are merged with existing values. + * @see https://on.cypress.io/env + * @example + * Cypress.env({ host: "http://server.dev.local", foo: "foo" }) + */ env(object: ObjectLike): void + /** + * Internal options for "cy.log" used in custom commands. + * + * @see https://on.cypress.io/cypress-log + */ log(options: Partial): Log /** @@ -449,6 +477,14 @@ declare namespace Cypress { * cy.contains('ul', 'apples') */ contains(content: string | number | RegExp): Chainable + /** + * Get the child DOM element that contains given text. + * + * @see https://on.cypress.io/contains + * @example + * // Yield el in .nav containing 'About' + * cy.get('.nav').contains('About') + */ contains(content: string | number | RegExp): Chainable> /** * Get the DOM element with name "selector" containing the text or regular expression. @@ -533,7 +569,17 @@ declare namespace Cypress { * @see https://on.cypress.io/filter */ filter(selector: K, options?: Partial): Chainable> // automatically returns the correct HTMLElement type + /** + * Get the DOM elements that match a specific selector. Opposite of `.not()` + * + * @see https://on.cypress.io/filter + */ filter(selector: string, options?: Partial): Chainable> + /** + * Get the DOM elements that match a specific selector. Opposite of `.not()` + * + * @see https://on.cypress.io/filter + */ filter(fn: (index: number, element: E) => boolean, options?: Partial): Chainable> /** @@ -544,6 +590,14 @@ declare namespace Cypress { * cy.get('.article').find('footer') // Yield 'footer' within '.article' */ find(selector: K, options?: Partial): Chainable> + /** + * Finds the descendent DOM elements with the given selector. + * + * @see https://on.cypress.io/find + * @example + * // Find the li’s within the nav + * cy.get('.left-nav>.nav').find('>li') + */ find(selector: string, options?: Partial): Chainable> /** @@ -559,6 +613,11 @@ declare namespace Cypress { * @see https://on.cypress.io/fixture */ fixture(path: string, options?: Partial): Chainable // no log? + /** + * Load a fixed set of data located in a file with given encoding. + * + * @see https://on.cypress.io/fixture + */ fixture(path: string, encoding: Encodings, options?: Partial): Chainable // no log? /** @@ -676,8 +735,18 @@ declare namespace Cypress { * Get the global `window.location` object of the page that is currently active. * * @see https://on.cypress.io/location + * @example + * cy.location() // Get location object */ location(options?: Partial): Chainable + /** + * Get a part of the global `window.location` object of the page that is currently active. + * + * @see https://on.cypress.io/location + * @example + * cy.location('host') // Get the host of the location object + * cy.location('port') // Get the port of the location object + */ location(key: string, options?: Partial): Chainable /** @@ -716,7 +785,17 @@ declare namespace Cypress { * @see https://on.cypress.io/nextall */ nextAll(selector: K, options?: Partial): Chainable> + /** + * Get all following siblings of each DOM element in a set of matched DOM elements. + * + * @see https://on.cypress.io/nextall + */ nextAll(options?: Partial): Chainable> + /** + * Get all following siblings of each DOM element in a set of matched DOM elements. + * + * @see https://on.cypress.io/nextall + */ nextAll(selector: string, options?: Partial): Chainable> /** @@ -725,7 +804,17 @@ declare namespace Cypress { * @see https://on.cypress.io/nextuntil */ nextUntil(selector: K, options?: Partial): Chainable> + /** + * Get all following siblings of each DOM element in a set of matched DOM elements up to, but not including, the element provided. + * + * @see https://on.cypress.io/nextuntil + */ nextUntil(options?: Partial): Chainable> + /** + * Get all following siblings of each DOM element in a set of matched DOM elements up to, but not including, the element provided. + * + * @see https://on.cypress.io/nextuntil + */ nextUntil(selector: string, options?: Partial): Chainable> /** @@ -753,7 +842,17 @@ declare namespace Cypress { * @see https://on.cypress.io/parent */ parent(selector: K, options?: Partial): Chainable> + /** + * Get the parent DOM element of a set of DOM elements. + * + * @see https://on.cypress.io/parent + */ parent(options?: Partial): Chainable> + /** + * Get the parent DOM element of a set of DOM elements. + * + * @see https://on.cypress.io/parent + */ parent(selector: string, options?: Partial): Chainable> /** @@ -762,7 +861,17 @@ declare namespace Cypress { * @see https://on.cypress.io/parents */ parents(selector: K, options?: Partial): Chainable> + /** + * Get the parent DOM elements of a set of DOM elements. + * + * @see https://on.cypress.io/parents + */ parents(options?: Partial): Chainable> + /** + * Get the parent DOM elements of a set of DOM elements. + * + * @see https://on.cypress.io/parents + */ parents(selector: string, options?: Partial): Chainable> /** @@ -771,7 +880,17 @@ declare namespace Cypress { * @see https://on.cypress.io/parentsuntil */ parentsUntil(selector: K, filter?: string, options?: Partial): Chainable> + /** + * Get all ancestors of each DOM element in a set of matched DOM elements up to, but not including, the element provided. + * + * @see https://on.cypress.io/parentsuntil + */ parentsUntil(selector: string, filter?: string, options?: Partial): Chainable> + /** + * Get all ancestors of each DOM element in a set of matched DOM elements up to, but not including, the element provided. + * + * @see https://on.cypress.io/parentsuntil + */ parentsUntil(element: E | JQuery, filter?: string, options?: Partial): Chainable> /** @@ -814,7 +933,19 @@ declare namespace Cypress { * @see https://on.cypress.io/prevall */ prevAll(selector: K, options?: Partial): Chainable> + /** + * Get all previous siblings of each DOM element in a set of matched DOM elements. + * > The querying behavior of this command matches exactly how [.prevAll()](http://api.jquery.com/prevAll) works in jQuery. + * + * @see https://on.cypress.io/prevall + */ prevAll(options?: Partial): Chainable> + /** + * Get all previous siblings of each DOM element in a set of matched DOM elements. + * > The querying behavior of this command matches exactly how [.prevAll()](http://api.jquery.com/prevAll) works in jQuery. + * + * @see https://on.cypress.io/prevall + */ prevAll(selector: string, options?: Partial): Chainable> /** @@ -824,7 +955,19 @@ declare namespace Cypress { * @see https://on.cypress.io/prevall */ prevUntil(selector: K, filter?: string, options?: Partial): Chainable> + /** + * Get all previous siblings of each DOM element in a set of matched DOM elements up to, but not including, the element provided. + * > The querying behavior of this command matches exactly how [.prevUntil()](http://api.jquery.com/prevUntil) works in jQuery. + * + * @see https://on.cypress.io/prevall + */ prevUntil(selector: string, filter?: string, options?: Partial): Chainable> + /** + * Get all previous siblings of each DOM element in a set of matched DOM elements up to, but not including, the element provided. + * > The querying behavior of this command matches exactly how [.prevUntil()](http://api.jquery.com/prevUntil) works in jQuery. + * + * @see https://on.cypress.io/prevall + */ prevUntil(element: E | JQuery, filter?: string, options?: Partial): Chainable> /** @@ -833,6 +976,13 @@ declare namespace Cypress { * @see https://on.cypress.io/readfile */ readFile(filePath: string, options?: Partial): Chainable + /** + * Read a file with given encoding and yield its contents. + * + * @see https://on.cypress.io/readfile + * @example + * cy.readFile('foo.json', 'utf8') + */ readFile(filePath: string, encoding: Encodings, options?: Partial): Chainable /** @@ -856,12 +1006,31 @@ declare namespace Cypress { reload(forceReload: boolean): Chainable /** - * Make an HTTP request. + * Make an HTTP GET request. * * @see https://on.cypress.io/request + * @example + * cy.request('http://dev.local/seed') */ request(url: string, body?: RequestBody): Chainable + /** + * Make an HTTP request with specific method. + * + * @see https://on.cypress.io/request + * @example + * cy.request('POST', 'http://localhost:8888/users', {name: 'Jane'}) + */ request(method: HttpMethod, url: string, body?: RequestBody): Chainable + /** + * Make an HTTP request with specific behavior. + * + * @see https://on.cypress.io/request + * @example + * cy.request({ + * url: '/dashboard', + * followRedirect: false // turn off following redirects + * }) + */ request(options: Partial): Chainable /** @@ -958,14 +1127,24 @@ declare namespace Cypress { * @see https://on.cypress.io/scrollto */ scrollTo(position: PositionType, options?: Partial): Chainable + /** + * Scroll to a specific X,Y position. + * + * @see https://on.cypress.io/scrollto + */ scrollTo(x: number | string, y: number | string, options?: Partial): Chainable /** - * Select an `