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


TypeScript core.MockMatchMedia類代碼示例

本文整理匯總了TypeScript中@angular/flex-layout/core.MockMatchMedia的典型用法代碼示例。如果您正苦於以下問題:TypeScript MockMatchMedia類的具體用法?TypeScript MockMatchMedia怎麽用?TypeScript MockMatchMedia使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: describe

describe('style directive', () => {
  let fixture: ComponentFixture<any>;
  let matchMedia: MockMatchMedia;
  let styler: StyleUtils;
  let createTestComponent = (template) => {
    fixture = makeCreateTestComponent(() => TestStyleComponent)(template);

    inject([MatchMedia, StyleUtils], (_matchMedia: MockMatchMedia, _styler: StyleUtils) => {
      matchMedia = _matchMedia;
      styler = _styler;
    })();
  };

  beforeEach(() => {
    jasmine.addMatchers(customMatchers);

    // Configure testbed to prepare services
    TestBed.configureTestingModule({
      imports: [CommonModule, CoreModule],
      declarations: [TestStyleComponent, LayoutDirective, StyleDirective],
      providers: [MockMatchMediaProvider]
    });
  });

  [
    {mq: 'xs', styleStr: "{'font-size': '15px'}", styleObj: {'font-size': '15px'}},
    {mq: 'sm', styleStr: "{'font-size': '16px'}", styleObj: {'font-size': '16px'}},
    {mq: 'md', styleStr: "{'font-size': '17px'}", styleObj: {'font-size': '17px'}},
    {mq: 'lg', styleStr: "{'font-size': '18px'}", styleObj: {'font-size': '18px'}}
  ]
  .forEach(testData => {
    it(`should apply '${testData.styleStr}' with '${testData.mq}' media query`, () => {
      createTestComponent(`
        <div [ngStyle.${testData.mq}]="${testData.styleStr}">
        </div>
    `);
      matchMedia.activate(testData.mq);
      expectNativeEl(fixture).toHaveStyle(testData.styleObj, styler);
    });
  });

  it('should merge with default inline styles', () => {
    createTestComponent(`
        <div style="color: blue" [ngStyle.xs]="{'font-size.px': '15'}">
        </div>
    `);
    expectNativeEl(fixture).toHaveStyle({color: 'blue'}, styler);
    matchMedia.activate('xs');
    expectNativeEl(fixture).toHaveStyle({color: 'blue', 'font-size': '15px'}, styler);
  });

  it('should support raw-string notations', () => {
    createTestComponent(`
        <div
            style="color: blue"
            ngStyle.xs="font-size: 15px; background-color: #fc2929;" >
        </div>
    `);
    expectNativeEl(fixture).toHaveStyle({color: 'blue'}, styler);
    matchMedia.activate('xs');

    expectNativeEl(fixture).toHaveStyle({
      'color': 'blue',
      'font-size': '15px'
    }, styler);

    // TODO(CaerusKaru): the Domino server impl. does not process colors correctly
    const backgroundColor = styler.lookupStyle(fixture.debugElement.children[0].nativeElement,
      'background-color');
    const hasBackgroundRaw = backgroundColor === '#fc2929';
    const hasBackgroundFormat = backgroundColor === 'rgb(252, 41, 41)';
    const hasBackground = hasBackgroundFormat || hasBackgroundRaw;

    expect(hasBackground).toBe(true);
  });

  it('should allow more than one responsive breakpoint on one element', () => {
    createTestComponent(`
      <div fxLayout
        [ngStyle]="{'font-size': '10px;', 'margin-left' : '13px'}"
        [ngStyle.xs]="{'font-size': '16px'}"
        [ngStyle.md]="{'font-size': '12px'}">
      </div>
    `);

    fixture.detectChanges();

    matchMedia.activate('xs');
    expectNativeEl(fixture).toHaveStyle({'display': 'flex'}, styler);
    expectNativeEl(fixture).toHaveStyle({'font-size': '16px'}, styler);
    expectNativeEl(fixture).not.toHaveStyle({'font-size': '12px'}, styler);

    matchMedia.activate('md');
    expectNativeEl(fixture).not.toHaveStyle({'font-size': '16px'}, styler);
    expectNativeEl(fixture).toHaveStyle({'font-size': '12px'}, styler);

    matchMedia.activate('lg');
    expectNativeEl(fixture).not.toHaveStyle({'font-size': '12px'}, styler);
    expectNativeEl(fixture).not.toHaveStyle({'font-size': '16px'}, styler);
    expectNativeEl(fixture).toHaveStyle({'font-size': '10px'}, styler);  // original is gone
//.........這裏部分代碼省略.........
開發者ID:marffox,項目名稱:flex-layout,代碼行數:101,代碼來源:style.spec.ts

示例2: it

  it('should allow more than one responsive breakpoint on one element', () => {
    createTestComponent(`
      <div fxLayout
        [ngStyle]="{'font-size': '10px;', 'margin-left' : '13px'}"
        [ngStyle.xs]="{'font-size': '16px'}"
        [ngStyle.md]="{'font-size': '12px'}">
      </div>
    `);

    fixture.detectChanges();

    matchMedia.activate('xs');
    expectNativeEl(fixture).toHaveStyle({'display': 'flex'}, styler);
    expectNativeEl(fixture).toHaveStyle({'font-size': '16px'}, styler);
    expectNativeEl(fixture).not.toHaveStyle({'font-size': '12px'}, styler);

    matchMedia.activate('md');
    expectNativeEl(fixture).not.toHaveStyle({'font-size': '16px'}, styler);
    expectNativeEl(fixture).toHaveStyle({'font-size': '12px'}, styler);

    matchMedia.activate('lg');
    expectNativeEl(fixture).not.toHaveStyle({'font-size': '12px'}, styler);
    expectNativeEl(fixture).not.toHaveStyle({'font-size': '16px'}, styler);
    expectNativeEl(fixture).toHaveStyle({'font-size': '10px'}, styler);  // original is gone
    expectNativeEl(fixture).toHaveStyle({'margin-left': '13px'}, styler);   // portion remains

  });
開發者ID:marffox,項目名稱:flex-layout,代碼行數:27,代碼來源:style.spec.ts


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