From 360b58b27ddb8f6e772ae23e875d8be6c1f8b83b Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Fri, 8 Jun 2018 11:47:24 -0400 Subject: [PATCH] Ts server yields 1907 (#1911) * types: cy.server yields default server options, close #1907 * add examples to a few TS commands --- cli/types/index.d.ts | 33 ++++++++++++++++++++++++++++++++- cli/types/tests/kitchen-sink.ts | 8 ++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/cli/types/index.d.ts b/cli/types/index.d.ts index 57b50cf504..8de20ec85e 100644 --- a/cli/types/index.d.ts +++ b/cli/types/index.d.ts @@ -798,9 +798,20 @@ declare namespace Cypress { /** * Start a server to begin routing responses to `cy.route()` and `cy.request()`. * + * @example + * // start server + * cy.server() + * // get default server options + * cy.server().should((server) => { + * expect(server.delay).to.eq(0) + * expect(server.method).to.eq('GET') + * expect(server.status).to.eq(200) + * // and many others options + * }) + * * @see https://on.cypress.io/server */ - server(options?: Partial): Chainable + server(options?: Partial): Chainable /** * Set a browser cookie. @@ -924,6 +935,15 @@ declare namespace Cypress { * Uncheck checkbox(es). * * @see https://on.cypress.io/uncheck + * @example + * // Unchecks checkbox element + * cy.get('[type="checkbox"]').uncheck() + * // Uncheck element with the id ‘saveUserName’ + * cy.get('#saveUserName').uncheck() + * // Uncheck all checkboxes + * cy.get(':checkbox').uncheck() + * // Uncheck the checkbox with the value of ‘ga’ + * cy.get('input[type="checkbox"]').uncheck(['ga']) */ uncheck(options?: Partial): Chainable uncheck(value: string, options?: Partial): Chainable @@ -941,6 +961,11 @@ declare namespace Cypress { * Control the size and orientation of the screen for your application. * * @see https://on.cypress.io/viewport + * @example + * // Set viewport to 550px x 750px + * cy.viewport(550, 750) + * // Set viewport to 357px x 667px + * cy.viewport('iphone-6') */ viewport(preset: ViewportPreset, orientation?: ViewportOrientation, options?: Partial): Chainable viewport(width: number, height: number, options?: Partial): Chainable @@ -1000,6 +1025,11 @@ declare namespace Cypress { * Yield the object passed into `.wrap()`. * * @see https://on.cypress.io/wrap + * @example + * // Make assertions about object + * cy.wrap({ amount: 10 }) + * .should('have.property', 'amount') + * .and('eq', 10) */ wrap(element: E | JQuery, options?: Partial): Chainable> wrap(object: S, options?: Partial): Chainable @@ -2994,6 +3024,7 @@ declare namespace Cypress { */ (chainers: string, value?: any): Chainable (chainers: string, value: any, match: any): Chainable + /** * Create an assertion. Assertions are automatically retried until they pass or time out. * Passing a function to `.should()` enables you to make multiple assertions on the yielded subject. This also gives you the opportunity to massage what you’d like to assert on. diff --git a/cli/types/tests/kitchen-sink.ts b/cli/types/tests/kitchen-sink.ts index 85c838b11b..7cdc2a628d 100644 --- a/cli/types/tests/kitchen-sink.ts +++ b/cli/types/tests/kitchen-sink.ts @@ -1539,6 +1539,14 @@ Cypress.minimatch('/users/1/comments', '/users/*/comments', { matchBase: true, }) +// check if cy.server() yields default server options +cy.server().should((server) => { + server // $ExpectType ServerOptions + expect(server.delay).to.eq(0) + expect(server.method).to.eq('GET') + expect(server.status).to.eq(200) +}) + cy.visit('https://www.acme.com/', { auth: { username: 'wile',