有人可以告诉我如何在比较这种情况时返回新数据。使用香草JavaScript。
{
"48": "{\"sid\":\"48\",\"name\":\"title 1\"}",
"77": "{\"sid\":\"77\",\"name\":\"The blahblah title\"}"
}
Run Code Online (Sandbox Code Playgroud)
与此相比
{
"48": "{\"sid\":\"48\",\"name\":\"title 1\"}",
"77": "{\"sid\":\"77\",\"name\":\"The blahblah title\"}",
"83": "{\"sid\":\"83\",\"name\":\"The blahblah derp\"}",
"87": "{\"sid\":\"87\",\"name\":\"The derpy title 4\"}"
}
Run Code Online (Sandbox Code Playgroud)
它应该只返回差异。
{
"83": "{\"sid\":\"83\",\"name\":\"The blahblah derp\"}",
"87": "{\"sid\":\"87\",\"name\":\"The derpy title 4\"}"
}
Run Code Online (Sandbox Code Playgroud) 我做了一个一次性订阅,debounceTime在我的组件上有一个管道onInit:
this.subscriptions.add(
this.updateJobs$
.pipe(
filter(jobs => !!jobs.length),
debounceTime(MyComponent.ListStabilizationTimeInMS),
first(),
)
.subscribe((jobs: Update[]) => {
// some code
})
);
Run Code Online (Sandbox Code Playgroud)
因此,我需要discardPeriodicTasks();在每次fakeAsync测试后将其作为最后一行包含在内,我觉得这很乏味。否则我会收到Error: 1 periodic timer(s) still in the queue.所有测试的错误。
我试图创建一个afterEach:
afterEach(()=> {
discardPeriodicTasks();
});
afterEach(fakeAsync(()=> {
discardPeriodicTasks();
}));
Run Code Online (Sandbox Code Playgroud)
但它不起作用,通过测试的唯一方法是手动附加discardPeriodicTasks();到所有测试用例。如果可以自动化就太好了。
我在人们使用振荡器节点.disconnect()后使用的几个教程中看到过.stop().
据我所知,振荡器节点是一次性的,所以当它停止并被扔掉时,它是否也会断开连接?
我理解错了吗?为什么我需要在使用.disconnect()后使用.stop()?
我需要将tappable指令添加到ion-card自定义组件内的组件.我用的@Input() myInputBool是:
<ng-container *ngIf="myInputBool">
<ion-card tappable>
<ng-container render="myContent"></ng-container>
</ion-card>
</ng-container>
<ng-container *ngIf="!myInputBool">
<ion-card tappable>
<ng-container render="myContent"></ng-container>
</ion-card>
</ng-container>
<ng-container #myContent>
This is my content
</ng-container>
Run Code Online (Sandbox Code Playgroud)
当然它不起作用,因为没有"渲染"选项.到目前为止,我的解决方法是在ng-container中添加一个不存在的变量
<ng-container *ngIf="thisVariableDoesNotExist else myContent"> </ng-container>
Run Code Online (Sandbox Code Playgroud)
但它感觉很糟糕和黑客.有更好的方法吗?
我使用Ionic,某些scss文件具有以下格式:
// Ionic Variables and Theming. For more info, please see:
// http://ionicframework.com/docs/v2/theming/
$font-path: "../assets/fonts";
@import "ionic.globals";
// Shared Variables
// --------------------------------------------------
// To customize the look and feel of this app, you can override
// the Sass variables found in Ionic's source scss files.
// To view all the possible Ionic variables, see:
// http://ionicframework.com/docs/v2/theming/overriding-ionic-variables/
// Named Color Variables
// --------------------------------------------------
// Named colors makes it easy to reuse colors on various components.
// It's highly recommended …Run Code Online (Sandbox Code Playgroud) 我有这个界面:
export interface AlertInteraction<T> {
id: AlertId;
data: T;
buttonId: AlertButtonId;
}
Run Code Online (Sandbox Code Playgroud)
但有时不需要数据。我知道我可以data: T将它声明为,但我想知道我是否可以这样:
export interface AlertInteraction<T> {
id: AlertId;
data: T;
buttonId: AlertButtonId;
}
export interface AlertInteraction {
id: AlertId;
buttonId: AlertButtonId;
}
Run Code Online (Sandbox Code Playgroud)
所以,如果我给,T那么我假设我想访问数据,如果没有,那么假设它不存在。是否可以?
我想为我的类定义一个接口,其中包含一个isValidConfig用作类型保护的函数。但我不知道如何声明。
我已经这样做了:
type AnyConfig = ConfigA | ConfigB | ConfigC;
public abstract isValidConfig<T extends AnyConfig>(config: AnyConfig): config is T;
Run Code Online (Sandbox Code Playgroud)
和
public abstract isValidConfig<T = AnyConfig>(config: T): config is T;
Run Code Online (Sandbox Code Playgroud)
但我在实现中总是遇到错误,例如:
public isValidConfig<T extends ConfigA >(config: T): config is T {
return config.type === TrainingTypes.A;
} /// Types of parameters 'config' and 'config' are incompatible.
Type 'T' is not assignable to type 'ConfigA '.
Run Code Online (Sandbox Code Playgroud)
是否有可能做到这一点?我还没有找到路。
我有一种类型,我想将对象键定义为可选,any如果我不给出任何值
type OptionalData<T> = T extends undefined ? { data?: any } : { data: T };
export type DataObject<T = any> = {
item?: string | null;
} & OptionalData<T>;
Run Code Online (Sandbox Code Playgroud)
它工作正常,直到我将我的通用设置为something | undefined
const data: DataObject<string | undefined> = { data: true }; // WRONG!
const data2: DataObject<string | number> = { data: true }; // CORRECT
Run Code Online (Sandbox Code Playgroud)
因为我的通用也可以扩展undefined我获取数据作为可选any
有没有办法说“any当它可以扩展时它只是可选的undefined”或者这样?
我正在将仅使用 jest 的组件单元测试迁移到使用 Testbed 和 jest 的 UI 测试(在我仅使用 jest 进行单元测试之前component = new MyCompontent())。
我正在使用 Angular 11。
有件事我不明白compileComponents。在文档中,它说“如果您只使用 CLI ng test 命令运行测试,则可以忽略此部分,因为 CLI 在运行测试之前编译应用程序。”
我没有打电话ng test,但jest --watch我的测试无论有没有都有效compileComponents(我所说的工作是指它们正确地断言了我的观点)。
还有一个“如果任何测试模块组件具有 templateUrl 或 styleUrls,则必须调用此方法,因为获取组件模板和样式文件必然是异步的”
我的组件同时使用templateUrl和styleUrls
@Component({
selector: 'app-my-example',
templateUrl: './my-example.component.html',
styleUrls: ['./my-example.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MyExampleComponent {}
Run Code Online (Sandbox Code Playgroud)
那么我缺少什么?我想确保如果我最终设置 CI 或类似的内容,我的测试不会中断。
或者我应该总是打电话compileComponents?我的印象是,如果不需要的话,这样做不会那么有效。
那么,具体什么时候compileComponents需要呢?
编辑:
这是我的笑话配置
module.exports = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/src/setupJest.ts'],
transformIgnorePatterns: …Run Code Online (Sandbox Code Playgroud) 注意:这不是Java switch 语句的重复:需要常量表达式,但它是常量,因为该链接的解决方案已在此处应用。
在带有打字稿的 Cordova 应用程序中,我使用此枚举来发送我的操作=
打字稿
enum PluginActions {
PICK = "PICK",
PICK_MULTIPLE = "PICK_MULTIPLE"
}
Run Code Online (Sandbox Code Playgroud)
我将其发送给 cordova,并在 Java 中将其作为我的方法中的字符串变量获取action。
@Override
public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException {
}
Run Code Online (Sandbox Code Playgroud)
那里我还有一个枚举。
爪哇
enum PickerActions {
PICK, PICK_MULTIPLE
}
Run Code Online (Sandbox Code Playgroud)
我想比较 typescriptPluginActions和 java PickerActions。
使用if我可以使用:
if (action.equals(PickerActions.PICK.name())) { }
但我想用一个开关来做到这一点,这样我就可以轻松添加更多操作
switch (action) {
case PickerActions.PICK.name():
JSONObject filters = inputs.optJSONObject(0);
this.chooseFile(filters, callbackContext);
return true;
default:
Log.w(this.LOGGER_TAG, "No function was found …Run Code Online (Sandbox Code Playgroud) angular ×4
typescript ×3
javascript ×2
jestjs ×2
enums ×1
ionic3 ×1
java ×1
object ×1
testbed ×1