• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript aurelia-binding.createScopeForTest函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中aurelia-binding.createScopeForTest函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createScopeForTest函数的具体用法?TypeScript createScopeForTest怎么用?TypeScript createScopeForTest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了createScopeForTest函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: it

  it('bind', () => {
    let bindingBehaviors = {
      oneTime: new OneTimeBindingBehavior(),
      oneWay: new OneWayBindingBehavior(),
      twoWay: new TwoWayBindingBehavior()
    };
    let lookupFunctions = { bindingBehaviors: name => bindingBehaviors[name] };
    let scope = createScopeForTest({ foo: 'bar' });
    let target = document.createElement('input');

    // one time
    let bindingExpression = bindingEngine.createBindingExpression('value', 'foo & oneTime', bindingMode.twoWay, lookupFunctions);
    let binding = bindingExpression.createBinding(target);
    binding.bind(scope);
    expect(binding.mode).toBe(bindingMode.oneTime);
    binding.unbind();

    // one way
    bindingExpression = bindingEngine.createBindingExpression('value', 'foo & oneWay', bindingMode.twoWay, lookupFunctions);
    binding = bindingExpression.createBinding(target);
    binding.bind(scope);
    expect(binding.mode).toBe(bindingMode.toView);
    binding.unbind();

    // two way
    bindingExpression = bindingEngine.createBindingExpression('value', 'foo & twoWay', bindingMode.oneTime, lookupFunctions);
    binding = bindingExpression.createBinding(target);
    binding.bind(scope);
    expect(binding.mode).toBe(bindingMode.twoWay);
    binding.unbind();
  });
开发者ID:aurelia,项目名称:templating-resources,代码行数:31,代码来源:binding-mode-behaviors.spec.ts


示例2: exerciseBehavior

    function exerciseBehavior(callback) {
      let sourceCalls = 0;
      let source = {
        handleClick: e => {
          // console.info('source called');
          sourceCalls++;
        }
      };
      let scope = createScopeForTest(source);

      // overrides updateSource
      binding.bind(scope);
      expect(binding.callSource === originalCallSource).not.toBe(true);

      for (let i = 0, ii = 50; i < ii; i++) {
        button.dispatchEvent(DOM.createCustomEvent('click', { bubbles: true }));
      }

      // How to ensure this happen after all events without timeout?
      let testDuration = 500;
      function endTest() {
        binding.unbind();
        expect(sourceCalls).toEqual(0);
        expect(binding.callSource === originalCallSource).toBe(true);
        callback();
      }
      setTimeout(endTest, testDuration);
    }
开发者ID:aurelia,项目名称:templating-resources,代码行数:28,代码来源:self-binding-behavior.spec.ts


示例3: it

  it('should apply update trigger events', () => {
    let source = { foo: 'bar' };
    let scope = createScopeForTest(source);
    let target = document.createElement('input');
    let bindingExpression = bindingEngine.createBindingExpression('value', `foo & updateTrigger:'blur':'paste'`, bindingMode.twoWay, lookupFunctions);
    let binding = bindingExpression.createBinding(target);

    binding.bind(scope);
    let targetHandler = binding.targetObserver.handler;

    target.value = 'baz';
    target.dispatchEvent(DOM.createCustomEvent('change'));
    expect(source.foo).toBe('bar');
    target.dispatchEvent(DOM.createCustomEvent('blur'));
    expect(source.foo).toBe('baz');

    target.value = 'bang';
    target.dispatchEvent(DOM.createCustomEvent('change'));
    expect(source.foo).toBe('baz');
    target.dispatchEvent(DOM.createCustomEvent('paste'));
    expect(source.foo).toBe('bang');


    binding.unbind();

    target.value = 'target';
    target.dispatchEvent(DOM.createCustomEvent('blur'));
    expect(source.foo).toBe('bang');
    target.dispatchEvent(DOM.createCustomEvent('paste'));
    expect(source.foo).toBe('bang');

    // also makes sure we disposed the listeners
    expect(targetHandler.element).toBe(null);
  });
开发者ID:aurelia,项目名称:templating-resources,代码行数:34,代码来源:update-trigger-binding-behavior.spec.ts


示例4: it

 it('should not throw in one-time binding', () => {
   let source = {};
   let scope = createScopeForTest(source);
   let target = document.createElement('input');
   let bindingExpression = bindingEngine.createBindingExpression('value', `'foo' & signal:'test'`, bindingMode.oneTime, lookupFunctions);
   let binding = bindingExpression.createBinding(target);
   expect(() => binding.bind(scope)).not.toThrow();
 });
开发者ID:aurelia,项目名称:templating-resources,代码行数:8,代码来源:signal-binding-behavior.spec.ts


示例5: exerciseBehavior

    function exerciseBehavior(callback) {
      let source = {};
      let scope = createScopeForTest(source);
      let _foo = '0';
      let last = null;
      let sourceUpdates = 0;
      Object.defineProperty(source, 'foo', {
        get: () => _foo,
        set: newValue => {
          // console.info(`SET FOO:  newValue=${newValue}; oldValue=${_foo}`);
          _foo = newValue;
          if (last !== null) {
            sourceUpdates++;
            let elapsed = new Date().getTime() - last;
            expect(elapsed).toBeGreaterThan(delay - 30);
            expect(elapsed).toBeLessThan(delay + 30);
            expect(target.value).toBe(newValue);
          }
          last = new Date();
        }
      });

      // overrides updateSource
      binding.bind(scope);
      expect(binding.updateSource === originalMethod).not.toBe(true);

      // subscribes
      let observer = bindingEngine.observerLocator.getObserver(source, 'foo');
      expect(observer.hasSubscribers()).toBe(true);
      let targetObserver = bindingEngine.observerLocator.getObserver(target, 'value');
      expect(targetObserver.hasSubscribers()).toBe(true);
      expect(targetObserver instanceof ValueAttributeObserver).toBe(true);

      // throttles
      let updateSourceInterval = setInterval(() => {
        let newValue = (parseInt(target.value, 10) + 1).toString();
        // console.info(`NOTIFYING:  newValue=${newValue}; oldValue=${target.value}`);
        target.value = newValue;
        target.dispatchEvent(DOM.createCustomEvent('change'));
      }, 20);

      let testDuration = 500;
      function endTest() {
        clearInterval(updateSourceInterval);
        binding.unbind();
        expect(sourceUpdates).toBeGreaterThan(Math.floor(testDuration / delay) - 1);
        expect(sourceUpdates).toBeLessThan(Math.floor(testDuration / delay) + 1);
        expect(binding.updateSource === originalMethod).toBe(true);
        expect(observer.hasSubscribers()).toBe(false);
        expect(targetObserver.hasSubscribers()).toBe(false);
        callback();
      }
      setTimeout(endTest, testDuration);
    }
开发者ID:aurelia,项目名称:templating-resources,代码行数:54,代码来源:throttle-binding-behavior.spec.ts


示例6: it

  it('should throttle target updates', done => {
    let source = { foo: 0 };
    let scope = createScopeForTest(source);
    let target = document.createElement('input');
    let delay = 150;
    let bindingExpression = bindingEngine.createBindingExpression('value', `foo & throttle:${delay}`, bindingMode.toView, lookupFunctions);
    let binding = bindingExpression.createBinding(target);
    let originalMethod = binding.updateTarget;

    function exerciseBehavior(callback) {
      // overrides updateTarget
      binding.bind(scope);
      expect(binding.updateTarget === originalMethod).not.toBe(true);

      // subscribes
      let observer = bindingEngine.observerLocator.getObserver(source, 'foo');
      expect(observer.hasSubscribers()).toBe(true);

      // throttles
      let lastTargetUpdate = new Date().getTime();
      let lastTargetValue = target.value;
      let targetUpdates = 0;
      let updateSourceInterval = setInterval(() => {
        source.foo++;
        if (target.value !== lastTargetValue) {
          // the target was updated... was it throttled?
          let elapsed = new Date().getTime() - lastTargetUpdate;
          expect(elapsed).toBeGreaterThan(delay - 30);
          expect(elapsed).toBeLessThan(delay + 30);
          // increment
          lastTargetUpdate = new Date().getTime();
          lastTargetValue = target.value;
          targetUpdates++;
        }
      }, 20);

      let testDuration = 500;
      function endTest() {
        clearInterval(updateSourceInterval);
        binding.unbind();
        expect(targetUpdates).toBeGreaterThan(Math.floor(testDuration / delay) - 1);
        expect(targetUpdates).toBeLessThan(Math.floor(testDuration / delay) + 1);
        expect(binding.updateTarget === originalMethod).toBe(true);
        expect(observer.hasSubscribers()).toBe(false);
        callback();
      }
      setTimeout(endTest, testDuration);
    }
    exerciseBehavior(() => exerciseBehavior(done));
  });
开发者ID:aurelia,项目名称:templating-resources,代码行数:50,代码来源:throttle-binding-behavior.spec.ts


示例7: it

 it('should bind attribute value', done => {
   const source = { foo: 'bar' };
   const scope = createScopeForTest(source);
   const target = document.createElement('div') as HTMLDivElement & { foo: any };
   const bindingExpression = bindingEngine.createBindingExpression('foo', `foo & attr`, bindingMode.toView, lookupFunctions);
   const binding = bindingExpression.createBinding(target);
   binding.bind(scope);
   expect(target.getAttribute('foo')).toBe('bar');
   expect(target.foo).toBe(undefined);
   source.foo = 'baz';
   setTimeout(() => {
     expect(target.getAttribute('foo')).toBe('baz');
     expect(target.foo).toBe(undefined);
     done();
   });
 });
开发者ID:aurelia,项目名称:templating-resources,代码行数:16,代码来源:attr-binding-behavior.spec.ts


示例8: it

  it('should debounce target updates', () => {
    let source = { foo: -1 };
    let scope = createScopeForTest(source);
    let target = DOM.createElement('input') as HTMLInputElement;
    let delay = 150;
    let bindingExpression = bindingEngine.createBindingExpression(
      'value',
      `foo & debounce:${delay}`,
      bindingMode.toView,
      lookupFunctions
    );
    let binding = bindingExpression.createBinding(target);
    let originalCallMethod = binding.call;

    // overrides call
    binding.bind(scope);
    expect(binding.call === originalCallMethod).not.toBe(true);

    // subscribes
    let observer = bindingEngine.observerLocator.getObserver(source, 'foo');
    expect(observer.hasSubscribers()).toBe(true);

    let lastValue = target.value;
    let exerciseTimes = 10;
    while (exerciseTimes--) {
      let tick = Math.floor(Math.random() * delay + delay / 3);
      // Greater than only will fail in case the tick is close to delay. ex: delay: 150, tick: 149, 150
      let shouldUpdate = tick >= delay;
      source.foo++;

      // updating in toView mode is controlled by taskqueue
      // constantly flush the queue to avoid waiting for the real queue to be flushed.
      bindingEngine.observerLocator.taskQueue.flushMicroTaskQueue();
      // console.log({ tick, shouldUpdate, val: target.value, foo: source.foo });

      // pull the trigger
      jasmine.clock().tick(tick);

      expect(target.value).toBe(shouldUpdate ? source.foo.toString() : lastValue);
      lastValue = target.value;
    }

    binding.unbind();
    expect(binding.call === originalCallMethod).toBe(true);
    expect(observer.hasSubscribers()).toBe(false);
  });
开发者ID:aurelia,项目名称:templating-resources,代码行数:46,代码来源:debounce-binding-behavior.spec.ts



注:本文中的aurelia-binding.createScopeForTest函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap