當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript assert.calledOn方法代碼示例

本文整理匯總了TypeScript中Sinon.assert.calledOn方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript assert.calledOn方法的具體用法?TypeScript assert.calledOn怎麽用?TypeScript assert.calledOn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Sinon.assert的用法示例。


在下文中一共展示了assert.calledOn方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

    it('should dispose items it owns', function() {
      const arr = obsArray<Foo>();
      const initial = [Foo.create(arr, 10), Foo.create(arr, 20), Foo.create(arr, 30)];
      arr.push(...initial);

      // Just to check what's in the array to start with.
      assert.lengthOf(arr.get(), 3);
      assert.deepEqual(arr.get(), initial);
      assert.notStrictEqual(arr.get(), initial);
      assertResetFirstArgs(fooConstruct, 10, 20, 30);
      sinon.assert.notCalled(fooDispose);

      // Delete two elements: they should get disposed, but the remaining one should not.
      const x = arr.splice(0, 2);
      assert.lengthOf(arr.get(), 1);
      assert.deepEqual(arr.get(), [initial[2]]);
      assert.lengthOf(x, 2);
      sinon.assert.calledOn(fooDispose.getCall(0), initial[0]);
      sinon.assert.calledOn(fooDispose.getCall(1), initial[1]);
      assertResetFirstArgs(fooDispose, 10, 20);
      assert.isTrue(initial[0].isDisposed());
      assert.isTrue(initial[1].isDisposed());
      assert.isFalse(initial[2].isDisposed());

      // Reassign: the remaining element should now also get disposed.
      let objects: Foo[];
      arr.set(objects = [Foo.create(arr, 40), Foo.create(arr, 50)]);
      assert.lengthOf(arr.get(), 2);
      assert.deepEqual(arr.get(), objects);
      assertResetFirstArgs(fooConstruct, 40, 50);
      assertResetSingleCall(fooDispose, initial[2], 30);
      assert.isTrue(initial[2].isDisposed());
      assert.isFalse(objects[0].isDisposed());
      assert.isFalse(objects[1].isDisposed());

      // Dispose the entire array: previously assigned elements should be disposed.
      arr.dispose();
      sinon.assert.notCalled(fooConstruct);
      assertResetFirstArgs(fooDispose, 40, 50);
      assert.isTrue(objects[0].isDisposed());
      assert.isTrue(objects[1].isDisposed());
    });
開發者ID:gristlabs,項目名稱:grainjs,代碼行數:42,代碼來源:obsArray.ts

示例2: assertResetSingleCall

export function assertResetSingleCall(spy: sinon.SinonSpy, context: any, ...args: any[]): void {
  sinon.assert.calledOnce(spy);
  sinon.assert.calledOn(spy, context);
  sinon.assert.calledWithExactly(spy, ...args);
  spy.resetHistory();
}
開發者ID:gristlabs,項目名稱:grainjs,代碼行數:6,代碼來源:testutil2.ts


注:本文中的Sinon.assert.calledOn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。