Skip to content

Commit

Permalink
elaborated strict mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dummy committed Feb 24, 2019
1 parent 1842020 commit 80b8032
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 34 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ console.log(fakeCalculator.divide(9, 5)); //prints 1338
- Doesn't rely on object instances - you can produce a strong-typed fake from nothing, ensuring that everything is mocked.

# Beware
## Names that conflict with Substitute.js
Let's say we have a class with a method called `received`, `didNotReceive` or `mimick` keyword - how do we mock it?

Simple! We disable the proxy methods temporarily while invoking the method by using the `disableFor` method which disables these special methods.
Expand All @@ -167,4 +168,18 @@ Substitute.disableFor(fake).received(1337);

//now we can assert that we received a call to the "received" method.
fake.received().received(1337);
```

## Strict mode
If you have `strict` set to `true` in your `tsconfig.json`, you may need to toggle off strict null checks. The framework does not currently support this.

However, it is only needed for your test projects anyway.

```json
{
"compilerOptions": {
"strict": true,
"strictNullChecks": false
}
}
```
4 changes: 2 additions & 2 deletions dist/spec/index.test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ export declare class Example {
a: string;
c(arg1: string, arg2: string): string;
readonly d: number;
v: string;
v: string | null | undefined;
received(stuff: number | string): void;
returnPromise(): Promise<Dummy>;
foo(): string;
foo(): string | undefined | null;
}
export {};
2 changes: 1 addition & 1 deletion dist/spec/index.test.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/src/Arguments.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export declare class AllArguments extends Argument<any> {
}
export declare class Arg {
static all(): AllArguments;
static any(): any;
static any(): Argument<any> & any;
static any<T extends 'string'>(type: T): Argument<string> & string;
static any<T extends 'number'>(type: T): Argument<number> & number;
static any<T extends 'boolean'>(type: T): Argument<boolean> & boolean;
static any<T extends 'array'>(type: T): Argument<any[]> & any[];
static any<T extends 'function'>(type: T): Argument<Function> & Function;
static any<T extends 'string' | 'number' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'array'>(type: T): any;
static is<T>(predicate: (input: T) => boolean): Argument<T> & T;
static any<T extends 'string' | 'number' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function' | 'array'>(type: T): Argument<any> & any;
static is<T>(predicate: (input: any) => boolean): Argument<T> & T;
private static toStringify;
}
2 changes: 1 addition & 1 deletion dist/src/Arguments.js.map

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

2 changes: 1 addition & 1 deletion dist/src/Transformations.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AllArguments } from "./Arguments";
export declare type NoArgumentFunctionSubstitute<TReturnType> = (() => (TReturnType & NoArgumentMockObjectMixin<TReturnType>));
export declare type FunctionSubstitute<TArguments extends any[], TReturnType> = ((...args: TArguments) => (TReturnType & MockObjectMixin<TArguments, TReturnType>)) & ((allArguments: AllArguments) => (TReturnType & MockObjectMixin<TArguments, TReturnType>));
export declare type PropertySubstitute<TReturnType> = TReturnType & Partial<NoArgumentMockObjectMixin<TReturnType>>;
export declare type PropertySubstitute<TReturnType> = (TReturnType & Partial<NoArgumentMockObjectMixin<TReturnType>>);
declare type BaseMockObjectMixin<TReturnType> = {
returns: (...args: TReturnType[]) => void;
};
Expand Down
2 changes: 1 addition & 1 deletion dist/src/Transformations.js.map

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

3 changes: 2 additions & 1 deletion dist/src/states/FunctionState.js

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

Loading

0 comments on commit 80b8032

Please sign in to comment.