0.0.2 • Published 4 years ago

create-spy-obj v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

create-spy-obj

Create jasmine spy objects magically

NPM version Build status Downloads

Usage

import { createSpyObj } from 'create-spy-obj';

class MyService {
  myMethod() {
    return 'foo';
  }
}

interface MyInterface {
  getName(): string;
}

// Use it with a class
const myServiceSpyObj = createSpyObj<MyService>();
myServiceSpyObj.myMethod.and.returnValue('bar');

// Use it with an interface
const myInterfaceSpyObj = createSpyObj<MyInterface>();
myInterfaceSpyObj.getName.and.returnValue('cool');

// Use it with a class without generics (can't do the same with interfaces)
const myServiceSpyObj = createSpyObj(MyService);
myServiceSpyObj.myMethod.and.returnValue('bar');

How it works

✨ Proxy magic ✨