ts-jest-mocker
Advanced tools
Comparing version
@@ -22,3 +22,3 @@ export declare type MockConfig = RequireAtLeastOne<MockConfigInternal>; | ||
export interface GlobalTsJestMocker { | ||
config?: MockConfig; | ||
tsJestMockerConfig?: MockConfig; | ||
} | ||
@@ -25,0 +25,0 @@ export declare namespace MergedConfig { |
@@ -36,3 +36,3 @@ "use strict"; | ||
function setConfig(config) { | ||
global.config = config; | ||
global.tsJestMockerConfig = config; | ||
} | ||
@@ -44,3 +44,3 @@ TsJestMocker.setConfig = setConfig; | ||
function getConfig() { | ||
return global.config; | ||
return global.tsJestMockerConfig; | ||
} | ||
@@ -47,0 +47,0 @@ TsJestMocker.getConfig = getConfig; |
@@ -6,2 +6,2 @@ import { Mock, MockConfig } from './types'; | ||
export declare function mock<T>(mockConfig?: MockConfig): Mock<T>; | ||
export { Mock } from './types'; | ||
export { Mock, MockConfig, TsJestMocker } from './types'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mock = void 0; | ||
exports.TsJestMocker = exports.mock = void 0; | ||
const proxy_class_1 = require("./proxy-class"); | ||
@@ -18,1 +18,3 @@ const proxy_generic_1 = require("./proxy-generic"); | ||
exports.mock = mock; | ||
var types_1 = require("./types"); | ||
Object.defineProperty(exports, "TsJestMocker", { enumerable: true, get: function () { return types_1.TsJestMocker; } }); |
@@ -12,2 +12,2 @@ /// <reference types="jest" /> | ||
}; | ||
export { MockConfig } from './config'; | ||
export { MockConfig, TsJestMocker } from './config'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TsJestMocker = void 0; | ||
var config_1 = require("./config"); | ||
Object.defineProperty(exports, "TsJestMocker", { enumerable: true, get: function () { return config_1.TsJestMocker; } }); |
{ | ||
"name": "ts-jest-mocker", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Powerful, lightweight and TypeScript friendly library that extends Jest with capability of mocking classes and interfaces.", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -153,2 +153,39 @@ <h1>ts-jest-mocker</h1> | ||
#### Local configuration | ||
```typescript | ||
mock(MyClass, { | ||
// config values | ||
}); | ||
``` | ||
#### Global config | ||
In order for configuration to be properly passed to test environments, you can define `ts-jest-mocker.setup.ts` configuration file | ||
and specify it in [setupFiles array](https://jestjs.io/docs/configuration#setupfiles-array) in | ||
[Jest configuration](https://jestjs.io/docs/configuration). | ||
##### ts-jest-mocker.setup.ts | ||
```typescript | ||
import { TsJestMocker } from 'ts-jest-mocker'; | ||
TsJestMocker.setConfig({ | ||
failIfMockNotProvided: false, | ||
}); | ||
``` | ||
##### jest.config.ts | ||
```typescript | ||
import type { Config } from 'jest'; | ||
const config: Config = { | ||
verbose: true, | ||
setupFiles: ['./ts-jest-mocker.setup.ts'], | ||
}; | ||
export default config; | ||
``` | ||
### Configuration options | ||
@@ -324,5 +361,5 @@ | ||
When using `ts-jest-mocker` + [RxJS](https://rxjs.dev/) for mocking interfaces, there could be issues like | ||
`Method schedule is not mocked` as reported under [this issue](!https://github.com/dariosn85/ts-jest-mocker/issues/6). | ||
`Method schedule is not mocked` as reported under [this issue](https://github.com/dariosn85/ts-jest-mocker/issues/6). | ||
Issue appears when you pass mock to an [of()][https://rxjs.dev/api/index/function/of] operator, as under the hood | ||
Issue appears when you pass mock to an [of()](https://rxjs.dev/api/index/function/of) operator, as under the hood | ||
operator internally checks if, so called, [Scheduler](https://rxjs.dev/guide/scheduler) was passed as a parameter. | ||
@@ -329,0 +366,0 @@ |
37459
3.29%602
0.84%394
10.36%