Skip to content

Commit 9f49588

Browse files
abramenalmefellows
authored andcommitted
feat(matching): add string type matcher. See #323 (#335)
1 parent 2ca9aba commit 9f49588

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ Often times, you find yourself having to re-write regular expressions for common
609609
| method | description |
610610
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
611611
| `boolean` | Match a boolean value (using equality) |
612+
| `string` | Match a string value |
612613
| `integer` | Will match all numbers that are integers (both ints and longs) |
613614
| `decimal` | Will match all real numbers (floating point and decimal) |
614615
| `hexadecimal` | Will match all hexadecimal encoded strings |
@@ -626,7 +627,7 @@ Often times, you find yourself having to re-write regular expressions for common
626627
### Match based on type
627628

628629
```javascript
629-
const { like } = Matchers
630+
const { like, string } = Matchers
630631

631632
provider.addInteraction({
632633
state: "Has some animals",
@@ -642,7 +643,7 @@ provider.addInteraction({
642643
},
643644
body: {
644645
id: 1,
645-
name: like("Billy"),
646+
name: string("Billy"),
646647
address: like({
647648
street: "123 Smith St",
648649
suburb: "Smithsville",

src/dsl/matchers.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
iso8601Time,
1616
rfc3339Timestamp,
1717
somethingLike,
18+
string,
1819
term,
1920
uuid,
2021
validateExample,
@@ -455,6 +456,16 @@ describe("Matcher", () => {
455456
})
456457
})
457458

459+
describe("#string", () => {
460+
describe("when given a valid string", () => {
461+
it("creates a valid matcher", () => {
462+
expect(string('test')).to.be.an("object")
463+
expect(integer()).to.be.an("object")
464+
expect(integer('test').contents).to.equal('test')
465+
})
466+
})
467+
})
468+
458469
describe("#decimal", () => {
459470
describe("when given a valid decimal", () => {
460471
it("creates a valid matcher", () => {

src/dsl/matchers.ts

+7
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ export function boolean(value: boolean = true) {
253253
return somethingLike<boolean>(value)
254254
}
255255

256+
/**
257+
* String Matcher.
258+
*/
259+
export function string(value: string = 'iloveorange') {
260+
return somethingLike<string>(value);
261+
}
262+
256263
// Convenience alias'
257264
export { somethingLike as like }
258265
export { term as regex }

0 commit comments

Comments
 (0)