1.0.0 • Published 4 years ago

@outstem/metis v1.0.0

Weekly downloads
133
License
-
Repository
-
Last release
4 years ago

Metis

Inspired by ng-bullet, Metis is a library that aims to enhance unit testing in Angular by simplifying workflow and drastically improving Test Times.

Installation

npm install --save-dev @outstem/metis
# Or
yarn add -D @outstem/metis

Usage

import {configureTestSuite} from '@outstem/metis';

// ...

configtureTestSuite(() =>
  TestBed.configureTestingModule({
    declarations: [
      /*list of components goes here*/
    ],
    imports: [
      /* list of providers goes here*/
    ],
  }),
);

Helper Functions

createTestContext

Creates TestCtx instance for the Angular Component which is not initialized yet (no ngOnInit called)

Use case: you can override Component's providers before hooks are called.

let ctx: TestCtx<MyComponent>

beforeEach(() => {
  const ctx = createTestContext(MyComponent);
});

its(('will render') => {
  expect(ctx.component).toBeTruthy();
})

createStableTestContext

Creates TestCtx instance for the Angular Component and ask Angular to perform change detection Angular lifecycle hooks (ngOninit) will be called when using this function to initialize the test context.

let ctx: TestCtx<MyComponent>

beforeEach(async () => {
  const ctx = await createStableTestContext(MyComponent);
});

its(('will render') => {
  expect(ctx.component).toBeTruthy();
})