forked from bahmutov/cypress-angular-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspec.ts
61 lines (54 loc) · 1.41 KB
/
spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/// <reference types="cypress" />
import { ApplicationRef, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import 'zone.js';
import { AppComponent } from '../../src/app/app.component';
// dynamic loading based on blog post
// https://blog.angularindepth.com/how-to-manually-bootstrap-an-angular-application-9a36ccf86429
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule
],
providers: [],
entryComponents: [AppComponent]
})
class AppModule {
app: ApplicationRef;
ngDoBootstrap(app: ApplicationRef) {
this.app = app;
}
}
/* 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();
cy.get('app-root').then(el$ => {
platformBrowserDynamic()
.bootstrapModule(AppModule)
.then(function (moduleRef) {
moduleRef.instance.app.bootstrap(AppComponent, el$.get(0));
});
});
});
it('works', () => {
cy.contains('Welcome to app').should('be.visible');
});
it('works again', () => {
cy.contains('Welcome to app').should('be.visible');
});
});