0.9.22 ā€¢ Published 2 years ago

@jscutlery/cypress-angular v0.9.22

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

Cypress Angular

@jscutlery/cypress-angular brings Angular support to Cypress Component Testing.

It is aiming to make Cypress Component Testing with Angular easier than writing code without tests šŸ˜œ.

šŸŖ„ Features

āœ… A simple mount function to test any of your components.

āœ… Mount options allow you to override style, providers, modules, child components...

āœ… Easy setup using Angular CLI schematics or Nx generators.

āœ… Using webpack configuration from Angular CLI to get the closest symmetry to production build. (i.e. no webpack hacks & less trouble)

āœ… Angular builder & Nx executor to run Cypress Component Tests.

šŸ¤¹šŸ»ā€ā™‚ļø Demo

Demo

Table of Contents

āœØ Usage

Mount a component

Add your .cy-spec.ts files in the e2e folder's *-e2e/src/components:

import { mount } from '@jscutlery/cypress-angular/mount';

describe(HelloComponent.name, () => {
  beforeEach(() => {
    mount(HelloComponent, {
      styles: [`body { background: purple}`],
      imports: [HelloModule],
    });
  });

  it('should show some love', () => {
    cy.get('h1').contains('ā¤ļø');
  });
});

Mount a template

describe(HelloComponent.name, () => {
  beforeEach(() => {
    mount(`<jc-hello></jc-hello>`, {
      imports: [HelloModule],
    });
  });

  it('should show some love', () => {
    cy.get('h1').contains('ā¤ļø');
  });
});

Mount a component with inputs

describe(HelloComponent.name, () => {
  beforeEach(() => {
    mount(HelloComponent, {
      inputs: {
        message: 'ā¤ļø',
      },
    });
  });

  it('should show some love', () => {
    cy.get('h1').contains('ā¤ļø');
  });
});

Mount a component with outputs

describe(NameComponent.name, () => {
  it('should trigger output', () => {
    const { nameChangeStub } = mountComponent();
    cy.get('input').type('Foo');
    cy.wrap(nameChangesStub).should('be.calledOnceWith', 'Foo');
  });

  function mountComponent() {
    const nameChangeStub = cy.stub();
    mount(NameComponent, {
      inputs: {
        nameChange: nameChangeStub,
      },
    });
    return { nameChangeStub };
  }
});

Storybook (and Component Story Format) support

You can also mount Storybook stories:

import { mountStory } from '@jscutlery/cypress-angular/mount';
import { Default } from './hello.stories.ts';

describe(HelloComponent.name, () => {
  beforeEach(() => mountStory(Default));

  it('should show some love', () => {
    cy.get('h1').contains('ā¤ļø');
  });
});

Destroy the component

If you want to destroy the component manually to test some tear down logic, you can use the destroy function:

import { destroy, mount } from '@jscutlery/cypress-angular/mount';

describe(HelloComponent.name, () => {
  beforeEach(() => {
    mount(`<jc-hello></jc-hello>`, {
      imports: [HelloModule],
    });
  });

  it('should show alert when destroyed', () => {
    destroy();
    cy.window().its('alert').should('be.called');
  });
});

šŸ›  Setup

Using Angular CLI:

ng add @jscutlery/cypress-angular
ng g @jscutlery/cypress-angular:setup-ct --project my-project

npx ngcc

ng run my-project:ct

Using Nx:

npm i -D @jscutlery/cypress-angular
nx g @jscutlery/cypress-angular:setup-ct --project my-project

npx ngcc

nx run my-project:ct
0.9.12

2 years ago

0.9.8

2 years ago

0.9.13

2 years ago

0.9.7

2 years ago

0.9.14

2 years ago

0.9.15

2 years ago

0.9.9

2 years ago

0.9.4

2 years ago

0.9.10

2 years ago

0.9.6

2 years ago

0.9.11

2 years ago

0.9.16

2 years ago

0.9.17

2 years ago

0.9.18

2 years ago

0.9.19

2 years ago

0.9.20

2 years ago

0.9.21

2 years ago

0.9.22

2 years ago

0.9.2

2 years ago

0.8.5

2 years ago

0.8.6

2 years ago

0.8.4

2 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago