-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added .not() matcher #81
Changes from 11 commits
b76f0e1
150a731
869810c
16c44f4
fc16cc1
7765611
b060b28
4f4ed84
c632a41
8c542fb
32bd8d8
02c16af
7f4947f
5bab836
b581f47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import {Matcher} from "./Matcher"; | ||
|
||
export class MatchingStringMatcher extends Matcher { | ||
export class MatchStringMatcher extends Matcher { | ||
constructor(private expectedValue: any) { | ||
super(); | ||
} | ||
|
||
public match(value: any): boolean { | ||
return value.match(this.expectedValue); | ||
return this.reverseResult(value.match(this.expectedValue)); | ||
} | ||
|
||
public toString(): string { | ||
return `match(${this.expectedValue})`; | ||
return `${this.prefix}match(${this.expectedValue})`; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
export class Matcher { | ||
public match(value: any): boolean { | ||
return false; | ||
private isNot: boolean = false; | ||
|
||
public match(...values: any[]): boolean { | ||
return this.reverseResult(false); | ||
} | ||
|
||
public toString(): string { | ||
return ""; | ||
return `${this.prefix}`; | ||
} | ||
|
||
public reverse() { | ||
this.isNot = true; | ||
return this; | ||
} | ||
|
||
protected get prefix(): string { | ||
return this.isNot ? "not()." : ""; | ||
} | ||
|
||
protected reverseResult(result: boolean): boolean { | ||
return this.isNot ? !result : result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {AnyFunctionMatcher} from "./AnyFunctionMatcher"; | ||
import {AnyNumberMatcher} from "./AnyNumberMatcher"; | ||
import {AnyOfClassMatcher} from "./AnyOfClassMatcher"; | ||
import {AnyStringMatcher} from "./AnyStringMatcher"; | ||
import {AnythingMatcher} from "./AnythingMatcher"; | ||
import {BetweenMatcher} from "./BetweenMatcher"; | ||
import {DeepEqualMatcher} from "./DeepEqualMatcher"; | ||
import {Matcher} from "./Matcher"; | ||
import {MatchStringMatcher} from "./MatchStringMatcher"; | ||
import {NotNullMatcher} from "./NotNullMatcher"; | ||
import {ObjectContainingMatcher} from "./ObjectContainingMatcher"; | ||
import {StrictEqualMatcher} from "./StrictEqualMatcher"; | ||
|
||
export class Not { | ||
|
||
public anyOfClass<T>(expectedClass: {new (...args: any[]): T}): Matcher { | ||
return (new AnyOfClassMatcher<T>(expectedClass)).reverse(); | ||
} | ||
|
||
public anyFunction(): Matcher { | ||
return (new AnyFunctionMatcher()).reverse(); | ||
} | ||
|
||
public anyNumber(): Matcher { | ||
return (new AnyNumberMatcher()).reverse(); | ||
} | ||
|
||
public anyString(): Matcher { | ||
return (new AnyStringMatcher()).reverse(); | ||
} | ||
|
||
public anything(): Matcher { | ||
return (new AnythingMatcher()).reverse(); | ||
} | ||
|
||
public between(min: number, max: number): Matcher { | ||
return (new BetweenMatcher(min, max)).reverse(); | ||
} | ||
|
||
public deepEqual(expectedValue: any): Matcher { | ||
return (new DeepEqualMatcher(expectedValue)).reverse(); | ||
} | ||
|
||
public notNull(): Matcher { | ||
return (new NotNullMatcher()).reverse(); | ||
} | ||
|
||
public strictEqual(expectedValue: any): Matcher { | ||
return (new StrictEqualMatcher(expectedValue)).reverse(); | ||
} | ||
|
||
public matchString(expectedValue: string | RegExp): Matcher { | ||
return (new MatchStringMatcher(expectedValue)).reverse(); | ||
} | ||
|
||
public objectContaining(expectedValue: Object): Matcher { | ||
return (new ObjectContainingMatcher(expectedValue)).reverse(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,8 @@ import {AnythingMatcher} from "./matcher/type/AnythingMatcher"; | |
import {BetweenMatcher} from "./matcher/type/BetweenMatcher"; | ||
import {DeepEqualMatcher} from "./matcher/type/DeepEqualMatcher"; | ||
import {Matcher} from "./matcher/type/Matcher"; | ||
import {MatchingStringMatcher} from "./matcher/type/MatchingStringMatcher"; | ||
import {MatchStringMatcher} from "./matcher/type/MatchStringMatcher"; | ||
import {Not} from "./matcher/type/Not"; | ||
import {NotNullMatcher} from "./matcher/type/NotNullMatcher"; | ||
import {ObjectContainingMatcher} from "./matcher/type/ObjectContainingMatcher"; | ||
import {StrictEqualMatcher} from "./matcher/type/StrictEqualMatcher"; | ||
|
@@ -33,7 +34,7 @@ export function spy<T>(instanceToSpy: T): T { | |
return new Spy(instanceToSpy).getMock(); | ||
} | ||
|
||
export function mock<T>(clazz: { new(...args: any[]): T; } | (Function & { prototype: T }) ): T { | ||
export function mock<T>(clazz: {new(...args: any[]): T; } | (Function & {prototype: T})): T { | ||
return new Mocker(clazz).getMock(); | ||
} | ||
|
||
|
@@ -78,7 +79,7 @@ export function resetCalls<T>(mockedValue: T): void { | |
(mockedValue as any).__tsmockitoMocker.resetCalls(); | ||
} | ||
|
||
export function anyOfClass<T>(expectedClass: { new (...args: any[]): T }): any { | ||
export function anyOfClass<T>(expectedClass: {new (...args: any[]): T}): any { | ||
return new AnyOfClassMatcher(expectedClass) as any; | ||
} | ||
|
||
|
@@ -114,14 +115,18 @@ export function strictEqual(expectedValue: any): Matcher { | |
return new StrictEqualMatcher(expectedValue); | ||
} | ||
|
||
export function match(expectedValue: RegExp | string): Matcher { | ||
return new MatchingStringMatcher(expectedValue); | ||
export function matchString(expectedValue: RegExp | string): Matcher { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Version with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or we can add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets leave it as match |
||
return new MatchStringMatcher(expectedValue); | ||
} | ||
|
||
export function objectContaining(expectedValue: Object): Matcher { | ||
return new ObjectContainingMatcher(expectedValue); | ||
} | ||
|
||
export function not(): Not { | ||
return new Not(); | ||
} | ||
|
||
import * as mockito from "./ts-mockito"; | ||
|
||
export default mockito; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
()
onanyNumber
-> should be:not().anyNumber()