-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/NagRock/ts-mockito
- Loading branch information
Showing
6 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {Matcher} from "./Matcher"; | ||
|
||
export class MatchingStringMatcher extends Matcher { | ||
constructor(private expectedValue: any) { | ||
super(); | ||
} | ||
|
||
public match(value: any): boolean { | ||
return value.match(this.expectedValue); | ||
} | ||
|
||
public toString(): string { | ||
return `match(${this.expectedValue})`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as _ from "lodash"; | ||
import {Matcher} from "./Matcher"; | ||
|
||
export class ObjectContainingMatcher extends Matcher { | ||
constructor(private expectedValue: any) { | ||
super(); | ||
} | ||
|
||
public match(value: Object): boolean { | ||
return _.isMatch(value, this.expectedValue); | ||
} | ||
|
||
public toString(): string { | ||
return `objectContaining(${this.expectedValue})`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {Matcher} from "../../../src/matcher/type/Matcher"; | ||
import {match} from "../../../src/ts-mockito"; | ||
|
||
describe("MatchingStringMatcher", () => { | ||
describe("checking if value matches given regexp", () => { | ||
const testObj: Matcher = match(/\w123/); | ||
|
||
describe("when given value matches regexp", () => { | ||
it("returns true", () => { | ||
// when | ||
const result = testObj.match("a123"); | ||
|
||
// then | ||
expect(result).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe("when given value doesn\'t match regexp", () => { | ||
it("returns false", () => { | ||
// when | ||
const result = testObj.match("123"); | ||
|
||
// then | ||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {Matcher} from "../../../src/matcher/type/Matcher"; | ||
import {objectContaining} from "../../../src/ts-mockito"; | ||
|
||
describe("ObjectContainingMatcher", () => { | ||
describe("checking if source object contains given object", () => { | ||
const testObj: Matcher = objectContaining({b: {c: "c", d: {}}}); | ||
|
||
describe("when given value contains given object", () => { | ||
it("returns true", () => { | ||
// when | ||
const result = testObj.match({a: "a", b: {c: "c", d: {}}}); | ||
|
||
// then | ||
expect(result).toBeTruthy(); | ||
}); | ||
|
||
it("returns true", () => { | ||
// when | ||
const result = testObj.match({b: {c: "c", d: {}}}); | ||
|
||
// then | ||
expect(result).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe("when given value doesn't contain given object", () => { | ||
it("returns false", () => { | ||
// when | ||
const result = testObj.match({b: {c: "c"}}); | ||
|
||
// then | ||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |