小编Cha*_*n15的帖子

如果角度2组件包含另一个组件,如何进行单元测试

我对棱角2很新.

我有一个组件,其模板中还有一些其他组件.

如何编写单元测试以检查我的父组件是否包含其他组件.

提及样本或指导我使用资源非常有帮助.

MyComponent.ts:

import { Component } from '@angular/core';
@Component({
selector: 'my-component',
templateUrl: `<div>
<other-component></other-component>
</div>`
})
export class MyComponent{

}
Run Code Online (Sandbox Code Playgroud)

OtherComponent.ts:

import { Component } from '@angular/core';
@Component({
selector: 'other-component',
templateUrl: `<div>
<h1>Other Component</h1>
</div>`
})
export class OtherComponent{

}
Run Code Online (Sandbox Code Playgroud)

karma-jasmine angular2-testing angular

17
推荐指数
2
解决办法
2万
查看次数

Nx CLI 运行许多命令不适用于多个应用程序

我尝试使用 Nx 来尝试使用 Monorepos。我一直面临着通过命令为多个应用程序提供服务的问题nx run-many。如果我做错了什么,有人可以纠正我吗?

\n

使用的命令:nx run-many --target=serve --all

\n

我可以看到 Nx 控制台记录所有可用的应用程序,但只运行一个

\n
>  NX  Running target serve for projects:\n  - app1\n  - app2\n\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\xe2\x80\x94\n> nx run app1:serve \n
Run Code Online (Sandbox Code Playgroud)\n

monorepo nrwl nrwl-nx

16
推荐指数
4
解决办法
2万
查看次数

在渲染之前,服务器不会等到http调用完成 - 角度4服务器端渲染

我已经开始实现角度通用,并能够通过服务器端渲染呈现html的静态部分.我面临的问题是,正在进行API调用,服务器正在呈现html而不等待http调用完成.因此,我的模板依赖于从api调用获得的数据的部分不会在服务器上呈现.

更多信息:

我在节点服务器中使用身份验证服务,只有在用户通过身份验证时才会为索引html提供身份验证,并在响应时设置cookie.

每当我从angular进行API调用时,我也会将cookie作为标头发送,因为依赖服务也会使用令牌验证用户.对于服务器端呈现,由于cookie在服务器级别不可用,我已成功注入请求并为API调用选择cookie.因此,API调用是成功的,但服务器不等待呈现,直到promise解析.

我试过的步骤没有成功:

我已根据此评论中的建议更改了我的区域版本https://github.com/angular/universal-starter/issues/181#issuecomment-250177280

如果需要进一步的信息,请告诉我.

将我引导到一个有角度的通用样板,它可以帮助我.

typescript server-side-rendering angular-universal angular

6
推荐指数
2
解决办法
1530
查看次数