我有一个标准的gulp测试观察器和我的Node.js/mocha设置的跑步者;
gulp.task('mocha', function() {
process.env.NODE_ENV = 'test';
return gulp.src(['./test/**/*.js'], {read: false})
.pipe(mocha({
recursive: true,
reporter: 'list',
ui: 'bdd'
})).on('error', gutil.log);
});
gulp.task('tests', function() {
gulp.watch(sources.concat(tests), ['mocha']);
});
Run Code Online (Sandbox Code Playgroud)
我想知道如何调整我的监视任务(和另一个)只向mocha发送已经改变的测试 - 这样我就不必等待20秒才能运行一百个测试.
我用fgulp-newer和gulp-cached尝试了这个,但没有运气.
我正在寻找一个答案或gulp插件的伪算法,然后我可以为此目的写:)
我正在使用本文中概述的typescript实现mongoose模型的过程:https://github.com/Appsilon/styleguide/wiki/mongoose-typescript-models并且我不确定在使用数组时这是如何转换的子文档.假设我有以下模型和模式定义:
interface IPet {
name: {type: mongoose.Types.String, required: true},
type: {type: mongoose.Types.String, required: true}
}
export = IPet
interface IUser {
email: string;
password: string;
displayName: string;
pets: mongoose.Types.DocumentArray<IPetModel>
};
export = IUser;
import mongoose = require("mongoose");
import IUser = require("../../shared/Users/IUser");
interface IUserModel extends IUser, mongoose.Document { }
import mongoose = require("mongoose");
import IPet = require("../../shared/Pets/IPet");
interface IPetModel extends IPet, Subdocument { }
Run Code Online (Sandbox Code Playgroud)
将新宠物添加到user.pet子文档的代码:
addNewPet = (userId: string, newPet: IPet){
var _user = mongoose.model<IUserModel>("User", userSchema);
let …Run Code Online (Sandbox Code Playgroud) 我想用模板形式[min]和[max]指令,所以我创造了他们和他们的工作.但测试让我感到困惑:验证不是异步执行的,但在更改了我的值和内容之后,我必须经历这个:
component.makeSomeChangeThatInvalidatesMyInput();
// control.invalid = false, expected
fixture.detectChanges();
// control.invalid is still false, not expected
// but if I go do this
fixture.whenStable().then(() => {
// control.invalid is STILL false, not expected
fixture.detectChanges();
// control.invalid now true
// expect(... .errors ... ) now passes
})
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我甚至需要这个whenStable(),更不用说另一个detectChanges()循环了.我在这里错过了什么?为什么我需要2个周期的变化检测才能执行此验证?
如果我运行测试无关紧要async.
这是我的测试:
@Component({
selector: 'test-cmp',
template: `<form>
<input [max]="maxValue" [(ngModel)]="numValue" name="numValue" #val="ngModel">
<span class="error" *ngIf="val.invalid">Errors there.</span>
</form>`
})
class TestMaxDirectiveComponent {
maxValue: number; …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Alfresco webscript中获取文档附加到的工作流列表,但我有点卡住了.
我最初的问题是我有一个文件列表,当前用户可能有这些文件分配给他的工作流程.所以,现在我想创建一个webscript,它将查看文件夹,获取所有文档,并将文档列表与任务引用一起组合,如果有当前用户的话.
我知道"工作流"对象,它为我提供了当前用户的工作流列表,但这不是我的问题的解决方案.
那么,我可以获得特定文档附加到的工作流列表吗?
这是从旧的WP插件中取出用于返回已签名的Amazon S3 URL的功能,但我无法让它工作!当我访问它返回的签名URL时,我得到:
The request signature we calculated does not match the signature you provided. Check your key and signing method.
function s3Url($text) {
$AWS_S3_KEY = 'KEY';
$AWS_S3_SECRET = 'SECRET';
$tag_pattern = '/(\[S3 bucket\=(.*?)\ text\=(.*?)\](.*?)\[\/S3\])/i';
define("AWS_S3_KEY", $AWS_S3_KEY); // replace this with your AWS S3 key
define("AWS_S3_SECRET", $AWS_S3_SECRET); // replace this with your secret key.
$expires = time()+get_option('expire_seconds');
if (preg_match_all ($tag_pattern, $text, $matches)) {
for ($m=0; $m<count($matches[0]); $m++) {
$bucket = $matches[2][$m];
$link_text = $matches[3][$m];
$resource = $matches[4][$m];
$string_to_sign = "GET\n\n\n$expires\n/".str_replace(".s3.amazonaws.com","",$bucket)."/$resource"; …Run Code Online (Sandbox Code Playgroud) 我试图让MongoDB聚合一个具有不同键值对的数组,而不知道键(只需一个简单的总和即可.)
示例文档:
{data: [{a: 3}, {b: 7}]}
{data: [{a: 5}, {c: 12}, {f: 25}]}
{data: [{f: 1}]}
{data: []}
Run Code Online (Sandbox Code Playgroud)
所以基本上每个doc(或它的数组真的)可以有0个或多个条目,我不知道这些对象的键,但我想对这些键的值求和并求平均值.
现在我只是加载一堆文档并在Node中自己完成,但是我想将这项工作卸载到MongoDB.
我知道我可以先解开那些,但是如何从那里开始呢?如果我不知道密钥,如何汇总/平均/最小/最大值?
我有一个用户表.当我点击一个用户时,我想要一个带有一些数据的模态.如何仅为辅助路由器触发路由更改?无论如何,我怎么会这样做呢?
我想要的主要是来自:
/users
Run Code Online (Sandbox Code Playgroud)
至
/users(aux:/user:12345)
Run Code Online (Sandbox Code Playgroud)
(12345将是userId.)
我最好想要在没有页面重新加载的情况下导航,当然:)
如何通过[routerLink]属性链接到此,以及如何通过手动调用router.navigate?
我不确定如何使用Angular2 Router最好地实现分页.
假设我有一个带有表的页面,带有一个简单的数字page参数:/table;page=1.
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'table-component',
template: `
<table> <tr *ngFor="let row of data"><td>{{ row.data }}</td></tr></table>
<button (click)="nextPage()">`
)
export class TableComponent implements OnInit {
public data: any[] = [];
private page: number = 1;
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.page = this.route.params.getValue('featuredSearch')
this.nextPage();
}
nextPage() {
this.page = this.page + 1;
this.APIService.get('data', this.page)
.then((data: any[]) => {
this.data = data;
}) …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
我有两个带有 ngx-bootstrap 的标签,如下所示,我想以编程方式停止标签功能 rom 工作:
<tabset>
<tab heading="First">Tab 1 content</tab>
<tab heading="Second">Tab 2 content</tab>
</tabset>
<label>Edit in progress: </label>
<input type="checkbox" [(ngModel)]="isTabSwitchEnabled">
Run Code Online (Sandbox Code Playgroud)
基本上,如果我在Tab 1 中有一个脏表单,我想弹出一个“放弃更改?” 在允许用户“导航”到Tab 2之前的对话框。我在 ngx-bootstrap tabs API 上没有看到我可以使用的任何内容。
我有一个示例Stackblitz,我尝试[disabled]在选项卡上使用它,它可以部分工作,但不能完全工作,因为我无法以编程方式设置选项卡处于活动状态(或者我不知道如何):
export class MyComponent {
disableSwitching: boolean;
@ViewChild('tabset') tabset: TabsetComponent;
@ViewChild('first') first: TabDirective;
@ViewChild('second') second: TabDirective;
confirmTabSwitch($event) {
if (this.disableSwitching) {
const confirm = window.confirm('Discard changes and switch tab?');
if (confirm) {
this.disableSwitching = false;
this.second.active = true;
}
} …Run Code Online (Sandbox Code Playgroud) angular ×5
mongodb ×2
node.js ×2
router ×2
typescript ×2
alfresco ×1
amazon-s3 ×1
angular-test ×1
gulp ×1
java ×1
javascript ×1
mocha.js ×1
mongoose ×1
php ×1
promise ×1
tabs ×1
tdd ×1
unit-testing ×1
validation ×1
vladivostok ×1
web-services ×1