LironHazan / qutilz

Opinionated specs gen for quick unit-tests setup including dependencies mocking

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

npm version

CLI tool for generating opinionated specs templates for a quick unit-tests setup.

Supports:

  • Dependencies mocking with the ts-mockito mocking library.

Run npx qutilz --specs from a local folder to generate a new spec template for local class-based components/services (Jest + ts-mockito) and for exported functions.

npx qutilz --report from the local tests' folder to print a report of all existing suites/tests.

Resources: background-blog-post

image

Examples:

  • For class methods testing:
export class AAA {
    constructor(private bbb: BBB) {}

    applyGreet() {
        this.bbb.greet();
    }
}

export class BBB {
  constructor() {}
  greet() {
    return 'hello!';
  }

  static help() {
    return 'help!';
  }
}

Qutilz will produce the following:

import { instance, mock, when } from 'ts-mockito';import { BBB } from './example-b';
  
describe('AAA', () => {

  // Mocked dependencies:
  const bbbMock = mock(BBB);
  const bbbInstance = instance(bbbMock);
  
  // Tested target: 
  const aAA = new AAA(bbbInstance);

  it('instance is truthy', () => {
    expect(aAA).toBeTruthy();
  });
  
  it('should test applyGreat', () => {
      expect(aAA.applyGreat).toBeTruthy();
    });
  
});

describe('BBB', () => {
  const bBB = new BBB();
  it('instance is truthy', () => {
    expect(bBB).toBeTruthy();
  });

  it('should test greet', () => {
    expect(bBB.greet).toBeTruthy();
  });

  it('should test help', () => {
    expect(BBB.help).toBeTruthy();
  });
});
  • For any file containing function declarations
export function foo() {
  return 'foo';
}

Qutilz will produce the following:

describe('Testing', () => {
  it('should test foo', () => {
    expect(foo).toBeTruthy();
  });
});

About

Opinionated specs gen for quick unit-tests setup including dependencies mocking

License:MIT License


Languages

Language:TypeScript 88.1%Language:JavaScript 11.9%