This file contains hidden or 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
| describe('getFormattedCustomerInfo-async', function(){ | |
| var customerService; | |
| var customerFormattingService; | |
| var $q; | |
| var $scope; | |
| beforeEach(function(){ | |
| module('customer'); | |
| inject( function($injector){ | |
| customerService = $injector.get('customer-service'); | |
| customerFormattingService = $injector.get('customer-formatting-service-async'); |
This file contains hidden or 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
| declare namespace Cypress { | |
| interface Chainable<Subject> { | |
| myCustomCommand(username: string, password: string): Cypress.Chainable<Response> | |
| } | |
| } | |
| Cypress.Commands.add('myCustomCommand', (username: string, password: string) => { | |
| Cypress.log({ | |
| name: 'loginByForm', |
This file contains hidden or 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
| interface Todo { | |
| id: string | |
| name: string | |
| done: boolean | |
| } | |
| const createTodo = (name: string) => new Promise<Todo>((resolve) => { | |
| setTimeout( | |
| resolve, | |
| 100, |
This file contains hidden or 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
| export const createTodo = (name: string) => { | |
| cy.get('.new-todo').type(`${name}{enter}`) | |
| return cy | |
| .get('.todo-list') | |
| .contains('li', name.trim()) | |
| .first() | |
| } | |
| export const updateTodo = (name: string) => ($todo: JQuery) => { |
This file contains hidden or 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
| export const createTodo = (todoDescription: string) => { | |
| // we use `any` here until this PR is accepted: https://github.com/cypress-io/cypress/pull/1289 | |
| const log: any = Cypress.log({ | |
| name: 'createTodo', // This should be pretty short. It shows up as all caps | |
| message: todoDescription, // Outputs to the right of the "name". This can be longer and will wrap | |
| consoleProps() { // Additional debug info. For example, cy.visit will show cookies and redirects | |
| return { | |
| 'Inserted Todo': todoDescription, | |
| } |
This file contains hidden or 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
| it('should allow chaining of all the helpers', () => { | |
| createTodo('Learn Cypress Command API') | |
| .then(updateTodo('Learn Cypress composition')) | |
| .then(markAsDone) | |
| .then(deleteTodo) | |
| cy.get('.todoapp') | |
| .should('not.contain', 'Learn Cypress composition') | |
| }) |
This file contains hidden or 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
| import expect from 'expect' | |
| describe('page', () => { | |
| it('should allow usage of expect directly from jest', () => { | |
| cy.wrap(5).should(subject => { | |
| expect(subject).toEqual(5) | |
| }) | |
| cy.wrap({ foo: 'bar' }).should(subject => { | |
| expect(subject).toHaveProperty('foo', 'bar') |
This file contains hidden or 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
| import expect from 'expect' | |
| // Put this in cypress/support/commands.js to use everywhere | |
| Cypress.Commands.overwrite('should', (originalFn, subject, expectation, ...args) => { | |
| // See if the expectation is a string and if it is a member of Jest's expect | |
| if (typeof expectation === 'string' && expect(subject)[expectation]) { | |
| return originalFn(subject, (s) => expect(s)[expectation](...args)) | |
| } | |
| return originalFn(subject, expectation, ...args) |
This file contains hidden or 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
| cy.wrap('foo').as('bar') | |
| cy.get('@bar').then(subject => { | |
| subject // JQuery<HTMLElement> | |
| console.log(subject) // logs 'foo' | |
| }) | |
| cy.get<string>('@bar').then(subject => { | |
| subject // string | |
| console.log(subject) // logs 'foo' |
This file contains hidden or 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
| const getFoo = cy.wrap('foo').createAlias() | |
| const getBar = cy.wrap('bar').createAlias() | |
| const getOne = cy.wrap(1).createAlias() | |
| // get one alias | |
| getFoo().then(subject => { | |
| subject // string | |
| console.log(subject) // logs 'foo' | |
| }) |
OlderNewer