0.9.1 • Published 2 years ago
@hexcore/mocker v0.9.1
Hexcore Mocker
Package moved to https://www.npmjs.com/package/@hexancore/mocker
Mocker package is super simple wrapper for Jest mocks util with extra stuff :).
Usage
import { Mocker } from '@hexcore/mocker';
interface TestMock {
a(param1: string, param2: boolean): boolean;
b(param1: string, param2: boolean): boolean;
}
// you can simply mock interface or class and give it descriptive name(used in errors)
const mock = Mocker.of<TestMock>("test_mock");
// define method call expectation(available methods list will be shows in VS)
mock.expects('a', 'test', true).andReturn(true);
// mock "i" attribute is object of mocked class, pass it where you need
mock.i.a('test', true);
// after execute your code, you can check sets expectations results with it(for many tests call it in jest "afterEach")
mock.checkExpections();
Defining expectation
Mocker::expects(method, ...args)
returns MethodMock
object with you can define return value by:
andReturnWith((implementation: (...args: any) => any)
- you can define your own method implementationandReturn(value: any)
- define returns passed value onceandReturnResolved
- simple sugar function for andReturnWith((() => Promise.resolve(value))
0.9.1
2 years ago
0.9.0
2 years ago
0.8.1
2 years ago
0.8.0
2 years ago
0.7.2
2 years ago
0.6.3
2 years ago
0.7.1
2 years ago
0.6.2
2 years ago
0.7.4
2 years ago
0.7.3
2 years ago
0.7.0
2 years ago
0.6.1
2 years ago
0.6.0
2 years ago
0.5.0
2 years ago
0.5.2
2 years ago
0.5.1
2 years ago
0.2.8
2 years ago
0.1.2
2 years ago
0.1.1
2 years ago
0.1.0
2 years ago