Skip to content

Instantly share code, notes, and snippets.

@meDavid
Last active January 14, 2019 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meDavid/f75880231ef3d11c15661f3d39fe9678 to your computer and use it in GitHub Desktop.
Save meDavid/f75880231ef3d11c15661f3d39fe9678 to your computer and use it in GitHub Desktop.
cypress angular unittest with private APIs
import { ɵrenderComponent as renderComponent, ɵcompileComponent as compileComponent} from '@angular/core';
import '@angular/compiler';
import 'zone.js';
import { AppComponent } from '../../src/app/app.component';
/* eslint-env mocha */
/* global cy */
describe('AppComponent', () => {
beforeEach(() => {
const html = `
<head>
<meta charset="UTF-8">
</head>
<body>
<app-root></app-root>
</body>
`;
const document = (cy as any).state('document');
document.write(html);
document.close();
// Quick hack to get the component definition, which in our case is the first annotation.
compileComponent(AppComponent, (<any>AppComponent).__annotations__[0]);
renderComponent(AppComponent, {
host: document.body
});
});
it('works', () => {
cy.contains('Welcome to angular-cypress-unit!').should('be.visible');
});
it('works again', () => {
cy.contains('Welcome to angular-cypress-unit!').should('be.visible');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment