Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
CalionVarduk committed Jun 23, 2020
2 parents 85ddc7b + b3efff5 commit 4132624
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 42 deletions.
18 changes: 9 additions & 9 deletions README.md
Expand Up @@ -15,7 +15,7 @@ If you are using `npm`, then simply run the `npm install frl-ts-mocking` CLI com

If you are using `yarn`, then go with the `yarn add frl-ts-mocking` command.

## B. The [mock\<T\>](https://github.com/CalionVarduk/ts-mocking/blob/master/src/core/mock.ts#L94) function
## B. The [mock\<T\>](https://github.com/CalionVarduk/ts-mocking/blob/master/src/mock.ts#L94) function

This function is the bread and butter of this project. As the name suggests, it allows you to create a mocked object.

Expand Down Expand Up @@ -53,7 +53,7 @@ const fooMock = mock<Foo>({

That's it!

## C. The [IMock\<T\>](https://github.com/CalionVarduk/ts-mocking/blob/master/src/core/mock.interface.ts) interface
## C. The [IMock\<T\>](https://github.com/CalionVarduk/ts-mocking/blob/master/src/mock.interface.ts) interface

Now, the `fooMock` object implements an `IMock<T>` interface, which contains some interesting members:

Expand All @@ -75,7 +75,7 @@ Now, the `fooMock` object implements an `IMock<T>` interface, which contains som
**NOTE:**<br/>
Be careful about using `instanceof` on `IMock<T>.subject`, e.g. `fooMock.subject instanceof Foo` will return `false`. The `mock` function doesn't actually create objects of type `T`. An exception to that rule are `IMock`s returned by the `partialMock` function, but more on that later in section `G`.

## D. The [IMockedPropertyInfo](https://github.com/CalionVarduk/ts-mocking/blob/master/src/core/mocked-property-info.interface.ts) interface
## D. The [IMockedPropertyInfo](https://github.com/CalionVarduk/ts-mocking/blob/master/src/mocked-property-info.interface.ts) interface

Calling the `getMemberInfo` method on our `fooMock` object with the `'property'` argument will return an invocation metadata object that implements the `IMockedPropertyInfo` interface.

Expand All @@ -85,13 +85,13 @@ const propertyInfo = fooMock.getMemberInfo('property') as IMockedPropertyInfo;

This interface has 3 members:

- `type` - specifies the invocation metadata type. For properties, it is always equal to `MockedInfoType.Property`. [MockedInfoType](https://github.com/CalionVarduk/ts-mocking/blob/master/src/core/mocked-info-type.enum.ts) is a simple enum that contains all possible invocation metadata types.
- `type` - specifies the invocation metadata type. For properties, it is always equal to `MockedInfoType.Property`. [MockedInfoType](https://github.com/CalionVarduk/ts-mocking/blob/master/src/mocked-info-type.enum.ts) is a simple enum that contains all possible invocation metadata types.

- `get` - returns the property's getter invocation metadata, if the getter has been mocked. Otherwise, it will return `null`.

- `set` - returns the property's setter invocation metadata, if the setter has been mocked. Otherwise, it will return `null`.

## E. The [IMockedMethodInfo](https://github.com/CalionVarduk/ts-mocking/blob/master/src/core/mocked-method-info.interface.ts) interface
## E. The [IMockedMethodInfo](https://github.com/CalionVarduk/ts-mocking/blob/master/src/mocked-method-info.interface.ts) interface

The `IMockedMethodInfo` represents single method's invocation metadata. Objects, that implement this interface, can be accessed by calling the `getMemberInfo` with an argument, that specifies a method's name, or by calling the `get` and `set` properties of the `IMockedPropertyInfo` objects.

Expand All @@ -111,7 +111,7 @@ This interface has 4 members:

- `clear` - clears all invocation data for this method and resets the counter.

## F. The [IInvocationData](https://github.com/CalionVarduk/ts-mocking/blob/master/src/core/invocation-data.interface.ts) interface
## F. The [IInvocationData](https://github.com/CalionVarduk/ts-mocking/blob/master/src/invocation-data.interface.ts) interface

The `IInvocationData` contains single invocation's properties, like:

Expand Down Expand Up @@ -163,7 +163,7 @@ const propertySetInvocation = propertySetInfo.getData(0);

And there we have it.

## G. The [partialMock\<T\>](https://github.com/CalionVarduk/ts-mocking/blob/master/src/core/mock.ts#L105) function
## G. The [partialMock\<T\>](https://github.com/CalionVarduk/ts-mocking/blob/master/src/mock.ts#L105) function

This function is very similar to the `mock<T>` function. The difference between these two is that the `partialMock<T>` allows you to modify an already existing object of type `T` and treat it as the mock subject, unlike the `mock<T>`, which creates the subject from scratch.

Expand Down Expand Up @@ -215,6 +215,6 @@ const barMock = partialMock<T>(bar, {

There are a few additional functions that don't really belong to any category. These are:

- [resetGlobalMockInvocationNo](https://github.com/CalionVarduk/ts-mocking/blob/master/src/core/mock.ts#L148) - allows to reset the `IInvocationData.globalNo` generator to `0`. This may for example be called before each test.
- [resetGlobalMockInvocationNo](https://github.com/CalionVarduk/ts-mocking/blob/master/src/mock.ts#L148) - allows to reset the `IInvocationData.globalNo` generator to `0`. This may for example be called before each test.

- [getGlobalMockInvocationNo](https://github.com/CalionVarduk/ts-mocking/blob/master/src/core/mock.ts#L154) - allows to lookup the next value for `IInvocationData.globalNo`.
- [getGlobalMockInvocationNo](https://github.com/CalionVarduk/ts-mocking/blob/master/src/mock.ts#L154) - allows to lookup the next value for `IInvocationData.globalNo`.
12 changes: 6 additions & 6 deletions jestconfig.json
@@ -1,8 +1,8 @@
{
"transform": {
"^.+\\.(t|j)sx?$": "ts-jest"
},
"testRegex": "/tests/.*\\.spec\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
}
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "/tests/.*\\.spec\\.(jsx?|tsx?)$",
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
}

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -44,6 +44,6 @@
"typescript": "3.1.6"
},
"dependencies": {
"frl-ts-utils": "^2.0.0"
"frl-ts-utils": "^2.2.1"
}
}
12 changes: 6 additions & 6 deletions src/index.ts
@@ -1,6 +1,6 @@
export * from './core/mocked-info-type.enum';
export * from './core/invocation-data.interface';
export * from './core/mocked-method-info.interface';
export * from './core/mocked-property-info.interface';
export * from './core/mock.interface';
export * from './core/mock';
export * from './mocked-info-type.enum';
export * from './invocation-data.interface';
export * from './mocked-method-info.interface';
export * from './mocked-property-info.interface';
export * from './mock.interface';
export * from './mock';
File renamed without changes.
2 changes: 1 addition & 1 deletion src/core/mock.interface.ts → src/mock.interface.ts
@@ -1,6 +1,6 @@
import { IMockedMethodInfo } from './mocked-method-info.interface';
import { IMockedPropertyInfo } from './mocked-property-info.interface';
import { Nullable } from 'frl-ts-utils/lib/core/nullable';
import { Nullable } from 'frl-ts-utils/lib/types/nullable';

/** Represents a mock proxy. */
export interface IMock<T>
Expand Down
10 changes: 5 additions & 5 deletions src/core/mock.ts → src/mock.ts
Expand Up @@ -3,11 +3,11 @@ import { IMockedMethodInfo } from './mocked-method-info.interface';
import { IMockedPropertyInfo } from './mocked-property-info.interface';
import { IInvocationData } from './invocation-data.interface';
import { IMock } from './mock.interface';
import { Nullable } from 'frl-ts-utils/lib/core/nullable';
import { reinterpretCast } from 'frl-ts-utils/lib/core/functions/reinterpret-cast';
import { isUndefined } from 'frl-ts-utils/lib/core/functions/is-undefined';
import { isPrimitiveOfType } from 'frl-ts-utils/lib/core/functions/primitive-cast';
import { Assert } from 'frl-ts-utils/lib/core/functions/assert';
import { Nullable } from 'frl-ts-utils/lib/types/nullable';
import { reinterpretCast } from 'frl-ts-utils/lib/functions/reinterpret-cast';
import { isUndefined } from 'frl-ts-utils/lib/functions/is-undefined';
import { isPrimitiveOfType } from 'frl-ts-utils/lib/functions/primitive-cast';
import { Assert } from 'frl-ts-utils/lib/functions/assert';

let GLOBAL_INVOCATION_NO = 0;

Expand Down
File renamed without changes.
@@ -1,6 +1,6 @@
import { MockedInfoType } from './mocked-info-type.enum';
import { IInvocationData } from './invocation-data.interface';
import { Nullable } from 'frl-ts-utils/lib/core/types/nullable';
import { Nullable } from 'frl-ts-utils/lib/types/nullable';

/** Stores mocked method information. */
export interface IMockedMethodInfo
Expand Down
@@ -1,6 +1,6 @@
import { MockedInfoType } from './mocked-info-type.enum';
import { IMockedMethodInfo } from './mocked-method-info.interface';
import { Nullable } from 'frl-ts-utils/lib/core/types/nullable';
import { Nullable } from 'frl-ts-utils/lib/types/nullable';

/** Stores mocked property information. */
export interface IMockedPropertyInfo
Expand Down
12 changes: 6 additions & 6 deletions src/tests/mock.spec.ts → tests/mock.spec.ts
@@ -1,9 +1,9 @@
import { MockedInfoType } from '../core/mocked-info-type.enum';
import { IMockedMethodInfo } from '../core/mocked-method-info.interface';
import { IMockedPropertyInfo } from '../core/mocked-property-info.interface';
import { IMock } from '../core/mock.interface';
import { mock, resetGlobalMockInvocationNo, getGlobalMockInvocationNo, partialMock } from '../core/mock';
import { reinterpretCast } from 'frl-ts-utils/lib/core/functions/reinterpret-cast';
import { MockedInfoType } from '../src/mocked-info-type.enum';
import { IMockedMethodInfo } from '../src/mocked-method-info.interface';
import { IMockedPropertyInfo } from '../src/mocked-property-info.interface';
import { IMock } from '../src/mock.interface';
import { mock, resetGlobalMockInvocationNo, getGlobalMockInvocationNo, partialMock } from '../src/mock';
import { reinterpretCast } from 'frl-ts-utils/lib/functions/reinterpret-cast';

abstract class Test
{
Expand Down
@@ -1,4 +1,4 @@
import { MockedInfoType } from '../core/mocked-info-type.enum';
import { MockedInfoType } from '../src/mocked-info-type.enum';

test('mocked info type uniqueness',
() =>
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Expand Up @@ -7,7 +7,7 @@
"strict": true,
"sourceMap": true
},
"include": ["src"],
"exclude": ["node_modules", "**/tests/*"]
"include": ["src", "tests"],
"exclude": ["node_modules", "tests", "lib"]
}

0 comments on commit 4132624

Please sign in to comment.