是)我有的:
我正在构建一个离子2应用程序,并构建了一个包含的基本角度2组件
输入字段
用于显示输入标题的标签
用于显示任何验证错误的标签
我将此称为我的输入组件
我有一个页面组件,上面有一个表单,目前有文本输入.1个常规输入(密码)和1个输入包装在我的输入组件(用户名)中.
这是我的页面组件的相关部分
ngOnInit() {
this.loginForm = this.formBuilder.group({
username: ['', Validators.required],
password: ['', Validators.required]
});
}
Run Code Online (Sandbox Code Playgroud)
这是页面组件模板
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()">
<!-- My input component -->
<aw-input-text id="username" name="Username" [formInput]="loginForm.controls.username"></aw-input-text>
<!-- A standard input control -->
<ion-item [class.error]="loginForm.controls.password.errors">
<ion-label floating>Password</ion-label>
<ion-input type="text" value="" name="password" formControlName="password"></ion-input>
<p *ngIf="loginForm.controls.password.errors">This field is required!</p>
</ion-item>
<button type="submit" class="custom-button" [disabled]="!loginForm.valid" block>Login</button>
</form>
Run Code Online (Sandbox Code Playgroud)
这是我输入组件的模板
<!-- Component template -->
<form [formGroup]="formGroup">
<ion-item>
<ion-label floating>{{inputName}}</ion-label>
<ion-input type="text" formControlName="inputValue"></ion-input>
<p *ngIf="!formGroup.controls.inputValue.valid">This field is required!</p>
</ion-item> …Run Code Online (Sandbox Code Playgroud) 我有一个按钮组件,它接受承诺并禁用按钮,直到承诺解决为止,并且我想为此功能编写单元测试。
我的按钮组件有一个承诺的输入
/**
* A single promise that triggers the busy state until it resolves
*/
@Input()
public promise: Promise<any>;
Run Code Online (Sandbox Code Playgroud)
在ngOnChanges内部,我听了承诺
/**
* Enable button busy state until promise resolves
*/
if (changes && changes.promise && changes.promise.currentValue) {
this.busyUntilPromiseResolves(changes.promise.currentValue);
}
Run Code Online (Sandbox Code Playgroud)
然后,我存储了一个有效的promise数组,以便可以传递多个promise
/**
* Add a promise that will keep the button in a busy state until it resolves
* @param activityProimise
*/
private busyUntilPromiseResolves(activityProimise) {
this.activityPromises.push(activityProimise);
activityProimise.then(() => {
this.activityPromises.splice(this.activityPromises.indexOf(activityProimise), 1);
});
}
Run Code Online (Sandbox Code Playgroud)
然后最后在我的模板中,如果数组中有任何promise,我将禁用按钮。
[disabled]="activityPromises.length > 0"
Run Code Online (Sandbox Code Playgroud)
unit-testing promise angular-components angular angular-unit-test
我在nodejs中使用cheerio来解析一些rss feed.我抓住所有将它们放入阵列的物品.我使用3个测试源,它们都为每个"item"元素都有一个"description"子元素.在其中一个Feed中,整个"描述"被包装为CDATA,我无法获得它的价值.这是一个缩写的代码片段
//Open the xml document with cheerio
$ = cheerio.load(arrXmlDocs[i],{ ignoreWhitespace : true, xmlMode : true});
//Loop through every item
$('item').each(function(i, xmlItem){
//array to hold each item being converted into an array
var tempArray = [];
//Loop through each child of <item>
$(xmlItem).children().each(function(i, xmlItem){
//Get the name
tempArray[$(this)[0].name] = $(this).text();
}
}
Run Code Online (Sandbox Code Playgroud)
正如所料,没有CDATA的两个RSS提供给我一个像这样的数组
[
[
name: 'name of episode',
description:'description of episode',
pubdate: 'published date'
],
[
name: 'name of episode',
description:'description of episode',
pubdate: 'published date'
]
] …Run Code Online (Sandbox Code Playgroud) angular ×2
javascript ×2
cdata ×1
cheerio ×1
forms ×1
node.js ×1
promise ×1
unit-testing ×1
xml ×1