Last active
January 14, 2019 13:45
-
-
Save meDavid/f75880231ef3d11c15661f3d39fe9678 to your computer and use it in GitHub Desktop.
cypress angular unittest with private APIs
This file contains 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 { ɵ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