-
Notifications
You must be signed in to change notification settings - Fork 947
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from Srokap/more_assertions
More assertions
- Loading branch information
Showing
3 changed files
with
369 additions
and
15 deletions.
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
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,103 @@ | ||
/** | ||
* We make ourselves compatible with AsymmetricMatcher class used by Jest | ||
* @see https://github.com/facebook/jest/blob/master/packages/expect/src/asymmetric_matchers.js | ||
* | ||
* Perhaps we can simplify that a bit and write only Jasmine-compatible matchers. | ||
* @see https://jasmine.github.io/2.4/introduction.html#section-Custom_asymmetric_equality_tester | ||
*/ | ||
class CustomAsymmetricMatcher { | ||
constructor() { | ||
// $$typeof is used internally by Jest and just to be sure let's use jest Symbol | ||
this.$$typeof = Symbol.for("jest.asymmetricMatcher") | ||
} | ||
} | ||
|
||
/** | ||
* Expect metric and imperial volume numbers in object. | ||
*/ | ||
class SpacexVolume extends CustomAsymmetricMatcher { | ||
asymmetricMatch(any) { | ||
expect(any).toEqual(expect.anything()) | ||
expect(any).toHaveProperty("cubic_meters", expect.any(Number)) | ||
expect(any).toHaveProperty("cubic_feet", expect.any(Number)) | ||
expect(any.cubic_meters).toBeGreaterThanOrEqual(0) | ||
expect(any.cubic_feet).toBeGreaterThanOrEqual(0) | ||
return true | ||
} | ||
|
||
toString() { | ||
return "SpacexVolume" | ||
} | ||
|
||
getExpectedType() { | ||
return "object" | ||
} | ||
|
||
toAsymmetricMatcher() { | ||
return "SpacexVolume" | ||
} | ||
} | ||
|
||
/** | ||
* Expect metric and imperial length (or dimension) numbers in object. | ||
*/ | ||
class SpacexLength extends CustomAsymmetricMatcher { | ||
asymmetricMatch(any) { | ||
expect(any).toEqual(expect.anything()) | ||
expect(any).toHaveProperty("meters", expect.any(Number)) | ||
expect(any).toHaveProperty("feet", expect.any(Number)) | ||
expect(any.meters).toBeGreaterThanOrEqual(0) | ||
expect(any.feet).toBeGreaterThanOrEqual(0) | ||
return true | ||
} | ||
|
||
toString() { | ||
return "SpacexLength" | ||
} | ||
|
||
getExpectedType() { | ||
return "object" | ||
} | ||
|
||
toAsymmetricMatcher() { | ||
return "SpacexLength" | ||
} | ||
} | ||
|
||
/** | ||
* Expect metric and imperial mass numbers in object. | ||
*/ | ||
class SpacexMass extends CustomAsymmetricMatcher { | ||
asymmetricMatch(any) { | ||
expect(any).toEqual(expect.anything()) | ||
expect(any).toHaveProperty("kg", expect.any(Number)) | ||
expect(any).toHaveProperty("lb", expect.any(Number)) | ||
expect(any.kg).toBeGreaterThanOrEqual(0) | ||
expect(any.lb).toBeGreaterThanOrEqual(0) | ||
return true | ||
} | ||
|
||
toString() { | ||
return "SpacexMass" | ||
} | ||
|
||
getExpectedType() { | ||
return "object" | ||
} | ||
|
||
toAsymmetricMatcher() { | ||
return "SpacexMass" | ||
} | ||
} | ||
|
||
module.exports = { | ||
volume: () => { | ||
return new SpacexVolume() | ||
}, | ||
length: () => { | ||
return new SpacexLength() | ||
}, | ||
mass: () => { | ||
return new SpacexMass() | ||
} | ||
} |
Oops, something went wrong.