当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript mock.Fakes类代码示例

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


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

示例1: it

    it('should grab the destination start and length correctly', () => {
      const targetStart = 12;
      const targetLength = 34;
      const currentStart = 56;
      const currentLength = 78;
      const selectedId = 'selectedId';

      const selectedTab = Mocks.object('selectedTab');
      const highlightElement = Mocks.object('highlightElement');
      Fakes.build(spyOn(tab, 'getStartPosition'))
          .when(highlightElement).return(currentStart)
          .when(selectedTab).return(targetStart);
      Fakes.build(spyOn(tab, 'getLength'))
          .when(highlightElement).return(currentLength)
          .when(selectedTab).return(targetLength);

      const mockElement = jasmine.createSpyObj('Element', ['querySelector']);
      mockElement.querySelector.and.returnValue(selectedTab);

      spyOn(tab, 'setHighlight_').and.returnValue(Promise.resolve());

      tab.updateHighlight_(selectedId, mockElement, highlightElement);
      assert(tab['setHighlight_']).to.haveBeenCalledWith(
          targetStart,
          targetLength,
          currentStart,
          currentLength);
      assert(mockElement.querySelector).to.haveBeenCalledWith(`[tab-id="${selectedId}"]`);
      assert(tab['getStartPosition']).to.haveBeenCalledWith(selectedTab);
      assert(tab['getLength']).to.haveBeenCalledWith(selectedTab);
      assert(tab['getStartPosition']).to.haveBeenCalledWith(highlightElement);
      assert(tab['getLength']).to.haveBeenCalledWith(highlightElement);
    });
开发者ID:garysoed,项目名称:gs-ui,代码行数:33,代码来源:base-tab_test.ts

示例2: it

    it('should return false if actionNormalDark on white is low contrast', () => {
      const baseNormalDark = Mocks.object('baseNormalDark');
      const baseReversedLight = Mocks.object('baseReversedLight');
      const actionNormalDark = Mocks.object('actionNormalDark');
      const actionNormalDarkest = Mocks.object('actionNormalDarkest');
      const actionNormalLight = Mocks.object('actionNormalLight');
      const actionReversedDark = Mocks.object('actionReversedDark');
      const actionReversedLight = Mocks.object('actionReversedLight');
      Fakes.build(spyOn(Theme, 'createShade_'))
          .when(Matchers.anyThing(), 0.25, false).return(actionNormalDark)
          .when(Matchers.anyThing(), 0, false).return(actionNormalDarkest)
          .when(Matchers.anyThing(), 0.75, false).return(actionNormalLight)
          .when(Matchers.anyThing(), 0.25, true).return(actionReversedDark)
          .when(Matchers.anyThing(), 0.75, true).return(actionReversedLight);

      const accentColor = Mocks.object('accentColor');
      Fakes.build(spyOn(Colors, 'getContrast'))
          .when(actionNormalDark, WHITE).return(10)
          .when(BLACK, actionNormalLight).return(13)
          .when(actionReversedLight, baseNormalDark).return(14)
          .when(WHITE, actionReversedDark).return(15)
          .when(actionReversedLight, BLACK).return(16)
          .when(actionNormalDarkest, baseReversedLight).return(17);

      const passes = Theme['isHighContrastAction_'](
          0.25,
          12,
          accentColor,
          baseNormalDark,
          baseReversedLight);
      assert(passes).to.beFalse();
    });
开发者ID:garysoed,项目名称:gs-ui,代码行数:32,代码来源:theme_test.ts

示例3: it

    it('should return the correct shade for reverseMode', () => {
      const backgroundColor = Mocks.object('backgroundColor');

      const hue = 78;
      const saturation = .9;
      const mockHueColor = jasmine.createSpyObj('HueColor', ['getHue', 'getSaturation']);
      mockHueColor.getHue.and.returnValue(hue);
      mockHueColor.getSaturation.and.returnValue(saturation);
      const idealContrast = 12;

      const distance = 0.34;
      spyOn(Solve, 'findThreshold').and.returnValue(distance);

      const testValue = 0.56;
      const testForeground = Mocks.object('testForeground');
      const shade = Mocks.object('shade');
      Fakes.build(spyOn(HslColor, 'newInstance'))
          .when(Matchers.anyThing(), Matchers.anyThing(), distance).return(shade)
          .when(Matchers.anyThing(), Matchers.anyThing(), testValue).return(testForeground);

      assert(input['getColorShade_'](backgroundColor, mockHueColor, idealContrast, true))
          .to.equal(shade);
      assert(HslColor.newInstance).to.haveBeenCalledWith(hue, saturation, distance);
      assert(Solve.findThreshold).to
          .haveBeenCalledWith(Matchers.any(Spec), Matchers.any(Function) as any, false);
    });
开发者ID:garysoed,项目名称:gs-ui,代码行数:26,代码来源:code-input_test.ts

示例4: it

 it(`should do nothing if the ID does not match`, () => {
   const mockMenuContainer = jasmine.createSpyObj('MenuContainer', ['setAttribute']);
   spyOn(service, 'getShownId_').and.returnValue(Symbol('otherId'));
   Fakes.build(spyOn(OverlayBus, 'dispatch')).call((_: any, fn: () => void) => fn());
   service.hideOverlay(Symbol('id'));
   assert(mockMenuContainer.setAttribute).toNot.haveBeenCalled();
   assert(OverlayBus.dispatch).toNot.haveBeenCalled();
 });
开发者ID:garysoed,项目名称:gs-ui,代码行数:8,代码来源:overlay-service_test.ts

示例5: it

    it(`should handle '.' and '/' correctly`, async () => {
      const value = './.';
      const normalizedValue = '___';
      const height = 12;
      const width = 34;
      const clientRect = {height, width} as any;
      const center = Vector2d.of(56, 78);
      const rootEl = document.createElement('div');
      spyOn(rootEl, 'getBoundingClientRect').and.returnValue(clientRect);
      const otherEl = document.createElement('div');
      otherEl.id = normalizedValue;
      rootEl.appendChild(otherEl);

      const containerEl = document.createElement('div');
      const slotContainerEl = document.createElement('div');
      const slotEl = document.createElement('slot');
      let callCount = 0;
      Fakes.build(mockDocument.createElement)
          .when('div').call(() => {
            const toReturn = callCount === 0 ? slotContainerEl : containerEl;
            callCount++;
            return toReturn;
          })
          .when('slot').return(slotEl);

      const lastAction = Mocks.object('lastAction');
      spyOn(ActionTracker, 'get').and.returnValue(Promise.resolve(lastAction));

      const mockContainerAnimation = jasmine.createSpyObj('ContainerAnimation', ['start']);
      const mockSlotAnimation = jasmine.createSpyObj('SlotAnimation', ['start']);

      spyOn(switchEl, 'computeAnimations_').and.returnValue({
        container: mockContainerAnimation,
        slot: mockSlotAnimation,
      });
      spyOn(switchEl, 'getAnimationCircleCenter_').and.returnValue(center);

      await switchEl.onValueChange_(value, rootEl);
      assert(mockSlotAnimation.start).to.haveBeenCalledWith(switchEl, `#${normalizedValue} > *`);
      assert(mockContainerAnimation.start).to.haveBeenCalledWith(switchEl, `#${normalizedValue}`);
      assert(rootEl).to.haveChildren([containerEl]);

      assert(containerEl).to.haveChildren([slotContainerEl]);
      assert(containerEl).to.haveClasses(['container']);
      assert(containerEl.id).to.equal(normalizedValue);

      assert(slotContainerEl).to.haveChildren([slotEl]);
      assert(slotContainerEl).to.haveClasses(['slotContainer']);
      assert(slotContainerEl.style).to
          .equal(Matchers.objectContaining({height: `${height}px`, width: `${width}px`}));

      assert(slotEl.getAttribute('name')).to.equal(value);

      assert(switchEl['computeAnimations_']).to.haveBeenCalledWith(clientRect, center);
      assert(switchEl['getAnimationCircleCenter_']).to.haveBeenCalledWith(lastAction);
    });
开发者ID:garysoed,项目名称:gs-ui,代码行数:56,代码来源:switch_test.ts


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