|
1 | 1 | import { |
2 | 2 | ComponentFixture, |
3 | | - TestComponentBuilder |
4 | | -} from '@angular/core/testing'; |
5 | | - |
6 | | -import { |
7 | 3 | async, |
8 | 4 | inject, |
9 | | - addProviders |
| 5 | + TestBed |
10 | 6 | } from '@angular/core/testing'; |
11 | | -import { provide, Component } from '@angular/core'; |
| 7 | +import { Component } from '@angular/core'; |
| 8 | + |
12 | 9 | import { ShellNoRender } from './shell-no-render.directive'; |
| 10 | +import { APP_SHELL_RUNTIME_PROVIDERS, APP_SHELL_BUILD_PROVIDERS } from './is-prerender.service'; |
13 | 11 | import { |
14 | | - APP_SHELL_BUILD_PROVIDERS, |
15 | | - APP_SHELL_RUNTIME_PROVIDERS |
16 | | -} from './is-prerender.service'; |
| 12 | + AppShellModule |
| 13 | +} from './index'; |
17 | 14 |
|
18 | 15 | @Component({ |
19 | 16 | selector: 'test-component', |
20 | | - template: `<div *shellNoRender>Rendered</div>`, |
21 | | - directives: [ShellNoRender] |
| 17 | + template: `<div *shellNoRender>Rendered</div>` |
22 | 18 | }) |
23 | 19 | class TestComponent {} |
24 | 20 |
|
25 | 21 | describe('ShellNoRender Directive', () => { |
| 22 | + |
26 | 23 | describe('prerender', () => { |
| 24 | + |
27 | 25 | beforeEach(() => { |
28 | | - addProviders([APP_SHELL_BUILD_PROVIDERS]); |
| 26 | + TestBed.configureTestingModule({ |
| 27 | + imports: [AppShellModule], |
| 28 | + providers: [APP_SHELL_BUILD_PROVIDERS], |
| 29 | + declarations: [TestComponent] |
| 30 | + }); |
| 31 | + TestBed.compileComponents(); |
29 | 32 | }); |
30 | 33 |
|
31 | | - it('should NOT render the element', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => { |
32 | | - return tcb.createAsync(TestComponent).then((fixture: ComponentFixture<TestComponent>) => { |
33 | | - fixture.detectChanges(); |
34 | | - expect(fixture.debugElement.childNodes.length).toBe(1); |
35 | | - expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}'); |
36 | | - }); |
37 | | - }))); |
| 34 | + it('should NOT render the element', () => { |
| 35 | + const fixture = TestBed.createComponent(TestComponent); |
| 36 | + fixture.detectChanges(); |
| 37 | + expect(fixture.debugElement.childNodes.length).toBe(1); |
| 38 | + expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}'); |
| 39 | + }); |
38 | 40 | }); |
39 | 41 |
|
40 | 42 |
|
41 | 43 | describe('runtime', () => { |
| 44 | + |
42 | 45 | beforeEach(() => { |
43 | | - addProviders([APP_SHELL_RUNTIME_PROVIDERS]); |
| 46 | + TestBed.configureTestingModule({ |
| 47 | + imports: [AppShellModule], |
| 48 | + providers: [APP_SHELL_RUNTIME_PROVIDERS], |
| 49 | + declarations: [TestComponent] |
| 50 | + }); |
| 51 | + TestBed.compileComponents(); |
44 | 52 | }); |
45 | 53 |
|
46 | | - it('should render the element', async(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => { |
47 | | - return tcb.createAsync(TestComponent).then((fixture: ComponentFixture<TestComponent>) => { |
48 | | - fixture.detectChanges(); |
49 | | - expect(fixture.debugElement.childNodes.length).toBe(2); |
50 | | - expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}'); |
51 | | - expect(fixture.debugElement.childNodes[1].nativeNode.textContent).toBe('Rendered'); |
52 | | - }); |
53 | | - }))); |
| 54 | + it('should render the element', () => { |
| 55 | + const fixture = TestBed.createComponent(TestComponent); |
| 56 | + fixture.detectChanges(); |
| 57 | + expect(fixture.debugElement.childNodes.length).toBe(2); |
| 58 | + expect(fixture.debugElement.childNodes[0].nativeNode.textContent).toBe('template bindings={}'); |
| 59 | + expect(fixture.debugElement.childNodes[1].nativeNode.textContent).toBe('Rendered'); |
| 60 | + }); |
54 | 61 | }); |
55 | 62 | }); |
0 commit comments