小编blo*_*ork的帖子

非id字段的环回关系

我想指定2个mssql表之间的关系.Paymentcategory和支付.paymentcategory.id加入payout.category列.

在payout.json模型中我指定为foreignKey:id,

"relations": {
    "paymentcategories": {
      "type": "hasOne",
      "model": "Paymentcategory",
      "foreignKey": "id"
 }
Run Code Online (Sandbox Code Playgroud)

但是对于id字段,loopback默认为primaryKey

有没有办法在类别字段上指定连接.最好在common/models/payout.json文件中?

"relations": {
    "paymentcategories": {
      "type": "hasOne",
      "model": "Paymentcategory",
      "foreignKey": "id",
      "primaryKey": "category" ??????????????????
 }
Run Code Online (Sandbox Code Playgroud)

现在我收到这个错误:

"error": {
"name": "Error",
"status": 400,
"message": "Key mismatch: Paymentpayout.id: undefined, Paymentcategory.id: 1",
"statusCode": 400,
Run Code Online (Sandbox Code Playgroud)

loopbackjs

6
推荐指数
1
解决办法
2097
查看次数

为什么jest.useFakeTimers不能使用RxJs Observable延迟

我想知道为什么jest.useFakeTimerssetTimeoutRxJs的延迟运算符一起工作但不是:

jest.useFakeTimers();
import {Observable} from 'rxjs/Observable';
import 'rxjs';

describe('timers', () => {
    it('should resolve setTimeout synchronously', () => {
        const spy = jest.fn();
        setTimeout(spy, 20);
        expect(spy).not.toHaveBeenCalled();
        jest.runTimersToTime(20);
        expect(spy).toHaveBeenCalledTimes(1);
    });
    it('should resolve setInterval synchronously', () => {
        const spy = jest.fn();
        setInterval(spy, 20);
        expect(spy).not.toHaveBeenCalled();
        jest.runTimersToTime(20);
        expect(spy).toHaveBeenCalledTimes(1);
        jest.runTimersToTime(20);
        expect(spy).toHaveBeenCalledTimes(2);
    });
    it('should work with observables', () => {
        const delay$ = Observable.of(true).delay(20);
        const spy = jest.fn();
        delay$.subscribe(spy);
        expect(spy).not.toHaveBeenCalled();
        jest.runTimersToTime(2000);
        expect(spy).toHaveBeenCalledTimes(1);
    });
});
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

仅供参考:使用20或2000作为参数jest.runTimersToTime没有任何区别.使用jest.runAllTimers()使测试过去

javascript unit-testing rxjs jestjs asynctest

3
推荐指数
1
解决办法
1316
查看次数

标签 统计

asynctest ×1

javascript ×1

jestjs ×1

loopbackjs ×1

rxjs ×1

unit-testing ×1