-
Notifications
You must be signed in to change notification settings - Fork 23
/
app.component.spec.ts
53 lines (34 loc) · 1.39 KB
/
app.component.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
import * as angular from 'angular';
import { IRender, renderFactory } from 'ng-metadata/testing';
import { NgModule, Component } from 'ng-metadata/core';
import { queryByDirective, createAngular1Module } from './shared/test-helpers';
import { AppComponent } from './app.component';
describe( `AppComponent`, () => {
@Component( {
selector: 'np-test-component',
template: `<np-app></np-app>`
} )
class TestComponent {
}
@NgModule( {
declarations: [ AppComponent, TestComponent ]
} )
class TestModule {
}
const TestModuleName = createAngular1Module( TestModule );
let render: IRender<TestComponent>;
beforeEach( angular.mock.module( TestModuleName ) );
beforeEach( angular.mock.inject( ( $injector: ng.auto.IInjectorService ) => {
const $compile = $injector.get<ng.ICompileService>( '$compile' );
const $rootScope = $injector.get<ng.IRootScopeService>( '$rootScope' );
const $scope = $rootScope.$new();
render = renderFactory( $compile, $scope );
} ) );
it( `should render Hello Pluto!!!`, () => {
const {compiledElement} = render(TestComponent);
// now we need to get our tested component
const { debugElement, componentInstance } = queryByDirective( compiledElement, AppComponent );
expect( componentInstance instanceof AppComponent ).toBe( true );
expect( debugElement.text() ).toContain( 'Hello from Pluto !' );
} );
} );