Skip to content

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

License

Notifications You must be signed in to change notification settings

LironHazan/qutilz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4fc4e19 · Aug 3, 2022

History

31 Commits
Dec 21, 2021
Nov 26, 2021
Nov 8, 2021
Nov 26, 2021
Nov 8, 2021
Nov 8, 2021
Nov 26, 2021
Sep 21, 2021
Aug 3, 2022
Nov 8, 2021
Nov 8, 2021
Nov 26, 2021
Nov 26, 2021
Sep 21, 2021

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published