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


TypeScript metadata_overrider.MetadataOverrider類代碼示例

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


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

示例1: describe

  describe('metadata overrider', () => {
    let overrider: MetadataOverrider;

    beforeEach(() => { overrider = new MetadataOverrider(); });

    it('should return a new instance with the same values', () => {
      const oldInstance = new SomeMetadata({plainProp: 'somePlainProp', getterProp: 'someInput'});
      const newInstance = overrider.overrideMetadata(SomeMetadata, oldInstance, {});
      expect(newInstance).not.toBe(oldInstance);
      expect(newInstance).toBeAnInstanceOf(SomeMetadata);
      expect(newInstance).toEqual(oldInstance);
    });

    it('should set individual properties and keep others', () => {
      const oldInstance =
          new SomeMetadata({plainProp: 'somePlainProp', getterProp: 'someGetterProp'});
      const newInstance =
          overrider.overrideMetadata(SomeMetadata, oldInstance, {set: {plainProp: 'newPlainProp'}});
      expect(newInstance)
          .toEqual(new SomeMetadata({plainProp: 'newPlainProp', getterProp: 'someGetterProp'}));
    });

    describe('add properties', () => {
      it('should replace non array values', () => {
        const oldInstance =
            new SomeMetadata({plainProp: 'somePlainProp', getterProp: 'someGetterProp'});
        const newInstance = overrider.overrideMetadata(
            SomeMetadata, oldInstance, {add: {plainProp: 'newPlainProp'}});
        expect(newInstance)
            .toEqual(new SomeMetadata({plainProp: 'newPlainProp', getterProp: 'someGetterProp'}));
      });

      it('should add to array values', () => {
        const oldInstance = new SomeMetadata({arrayProp: ['a']});
        const newInstance =
            overrider.overrideMetadata(SomeMetadata, oldInstance, {add: {arrayProp: ['b']}});
        expect(newInstance).toEqual(new SomeMetadata({arrayProp: ['a', 'b']}));
      });
    });

    describe('remove', () => {
      it('should set values to undefined if their value matches', () => {
        const oldInstance =
            new SomeMetadata({plainProp: 'somePlainProp', getterProp: 'someGetterProp'});
        const newInstance = overrider.overrideMetadata(
            SomeMetadata, oldInstance, {remove: {plainProp: 'somePlainProp'}});
        expect(newInstance)
            .toEqual(new SomeMetadata({plainProp: undefined, getterProp: 'someGetterProp'}));
      });

      it('should leave values if their value does not match', () => {
        const oldInstance =
            new SomeMetadata({plainProp: 'somePlainProp', getterProp: 'someGetterProp'});
        const newInstance = overrider.overrideMetadata(
            SomeMetadata, oldInstance, {remove: {plainProp: 'newPlainProp'}});
        expect(newInstance)
            .toEqual(new SomeMetadata({plainProp: 'somePlainProp', getterProp: 'someGetterProp'}));
      });

      it('should remove a value from an array', () => {
        const oldInstance =
            new SomeMetadata({arrayProp: ['a', 'b', 'c'], getterProp: 'someGetterProp'});
        const newInstance = overrider.overrideMetadata(
            SomeMetadata, oldInstance, {remove: {arrayProp: ['a', 'c']}});
        expect(newInstance)
            .toEqual(new SomeMetadata({arrayProp: ['b'], getterProp: 'someGetterProp'}));
      });

      it('should support types as values', () => {
        class Class1 {}
        class Class2 {}
        class Class3 {}

        const instance1 = new SomeMetadata({arrayProp: [Class1, Class2, Class3]});
        const instance2 =
            overrider.overrideMetadata(SomeMetadata, instance1, {remove: {arrayProp: [Class1]}});
        expect(instance2).toEqual(new SomeMetadata({arrayProp: [Class2, Class3]}));
        const instance3 =
            overrider.overrideMetadata(SomeMetadata, instance2, {remove: {arrayProp: [Class3]}});
        expect(instance3).toEqual(new SomeMetadata({arrayProp: [Class2]}));

      });
    });

    describe('subclasses', () => {
      it('should set individual properties and keep others', () => {
        const oldInstance = new OtherMetadata({
          plainProp: 'somePlainProp',
          getterProp: 'someGetterProp',
          otherPlainProp: 'newOtherProp'
        });
        const newInstance = overrider.overrideMetadata(
            OtherMetadata, oldInstance, {set: {plainProp: 'newPlainProp'}});
        expect(newInstance).toEqual(new OtherMetadata({
          plainProp: 'newPlainProp',
          getterProp: 'someGetterProp',
          otherPlainProp: 'newOtherProp'
        }));
      });

//.........這裏部分代碼省略.........
開發者ID:Cammisuli,項目名稱:angular,代碼行數:101,代碼來源:metadata_overrider_spec.ts

示例2: it

      it('should support types as values', () => {
        class Class1 {}
        class Class2 {}
        class Class3 {}

        const instance1 = new SomeMetadata({arrayProp: [Class1, Class2, Class3]});
        const instance2 =
            overrider.overrideMetadata(SomeMetadata, instance1, {remove: {arrayProp: [Class1]}});
        expect(instance2).toEqual(new SomeMetadata({arrayProp: [Class2, Class3]}));
        const instance3 =
            overrider.overrideMetadata(SomeMetadata, instance2, {remove: {arrayProp: [Class3]}});
        expect(instance3).toEqual(new SomeMetadata({arrayProp: [Class2]}));

      });
開發者ID:Cammisuli,項目名稱:angular,代碼行數:14,代碼來源:metadata_overrider_spec.ts

示例3: SomeMetadata

 it('should set values to undefined if their value matches', () => {
   const oldInstance =
       new SomeMetadata({plainProp: 'somePlainProp', getterProp: 'someGetterProp'});
   const newInstance = overrider.overrideMetadata(
       SomeMetadata, oldInstance, {remove: {plainProp: 'somePlainProp'}});
   expect(newInstance)
       .toEqual(new SomeMetadata({plainProp: undefined, getterProp: 'someGetterProp'}));
 });
開發者ID:Cammisuli,項目名稱:angular,代碼行數:8,代碼來源:metadata_overrider_spec.ts


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