# All files / src testHelper.ts

86.67% Statements 13/15
100% Branches 0/0
71.43% Functions 5/7
92.31% Lines 12/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28

    2x

    2x
    45x

    2x
    8x
    8x

    8x
    8x

    2x
    5x

    5x

    5x

     import {BuildContext, ObjectFactory} from 'typescript-ioc';
    import Mock = jest.Mock;

    export function factoryFromBuilder<T>(builder: (context: BuildContext) => T): ObjectFactory {
      return (context: BuildContext) => builder(context);
    }

    export function factoryFromValue<T>(value: T): ObjectFactory {
      return () => value;
    }

    export function setField<T>(obj: T, field: keyof T, mock: Mock): () => void {
      const oldValue = obj[field];
      obj[field] = mock as any;

      return () => {
        obj[field] = oldValue;
      }
    }

    export function mockField<T>(obj: T, field: keyof T): Mock {
      const mock: Mock = jest.fn();

      obj[field] = mock as any;

      return mock;
    }