|
1 | 1 |
|
2 | 2 | import { ServerModule } from '@angular/platform-server'; |
3 | | -import { NgModule, Component } from '@angular/core'; |
| 3 | +import { NgModule, Component, Inject, InjectionToken } from '@angular/core'; |
4 | 4 | import 'zone.js'; |
5 | 5 |
|
6 | 6 | import { BrowserModule } from '@angular/platform-browser'; |
@@ -88,4 +88,28 @@ describe('test runner', () => { |
88 | 88 | expect(result.error).toBeUndefined(); |
89 | 89 | done(); |
90 | 90 | }); |
| 91 | + it('should be able to inject some token', async(done) => { |
| 92 | + const SOME_TOKEN = new InjectionToken<string>('SOME_TOKEN'); |
| 93 | + const someValue = {message: 'value' + new Date()}; |
| 94 | + @Component({ |
| 95 | + selector: 'root', |
| 96 | + template: `message:{{_someToken.message}}` |
| 97 | + }) |
| 98 | + class MockComponent {constructor(@Inject(SOME_TOKEN) public readonly _someToken: any) {}} |
| 99 | + const appModule = makeTestingModule('', MockComponent); |
| 100 | + const server = await startSocketEngine(appModule, [{provide: SOME_TOKEN, useValue: someValue}]); |
| 101 | + |
| 102 | + const client = net.createConnection(9090, 'localhost', () => { |
| 103 | + const renderOptions = {id: 1, url: '/path', |
| 104 | + document: '<root></root>'} as SocketEngineRenderOptions; |
| 105 | + client.write(JSON.stringify(renderOptions)); |
| 106 | + }); |
| 107 | + |
| 108 | + client.on('data', data => { |
| 109 | + const res = JSON.parse(data.toString()) as SocketEngineResponse; |
| 110 | + server.close(); |
| 111 | + expect(res.html).toContain(someValue.message); |
| 112 | + done(); |
| 113 | + }); |
| 114 | + }); |
91 | 115 | }); |
0 commit comments