Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
mock-factory
Advanced tools
A Jasmine test util that uses a TyoeScript class or an instance of a class to create a mock instance of that class.
This util is built with and for Jasmine test framework. Basic understanding of Jasmine is assumed.
This util requires ES6 Proxy and only contains un-compiled *.ts
files which must be compiled with a TypeScript compiler.
npm install mock-factory --save-dev
Import the library with ES6 Module Syntax:
import { MockFactory } from 'mock-factory'
class RealClass {
// This is a typescript class
}
...
const mockInstance = MockFactory.create(RealClass);
const realInstance: RealInterface;
...
const mockInstance = MockFactory.create(realInstance);
MockFactory.create()
will return an object with the same interface as the original object. You can invoke methods and get/set properties on this object.
undefined
as the initial value. The value can be overwritten with anything.class RealClass {
public doSomething(...arg: any[]) { ... }
public someProperty = 'whatever';
}
const mockInstance = MockFactory.create(RealClass);
// get, set property
expect(mockInstance.someProperty).toBeUndefined();
mockInstance.someProperty = 'hello';
expect(mockInstance.someProperty).toBe('hello');
// use function spy
expect(mockInstance.doSomething).not.toHaveBeenCalled();
(mockInstance.doSomething as jasmine.Spy).and.returnValue('awesome!');
expect(mockInstance.doSomething(42)).toBe('awesome!');
expect(mockInstance.doSomething).toHaveBeenCalledWith(42);
This project is built with Angular CLI
Run ng test
to execute the unit tests via Karma.
FAQs
A Jasmine helper for creating mocked classes
The npm package mock-factory receives a total of 38 weekly downloads. As such, mock-factory popularity was classified as not popular.
We found that mock-factory demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.