-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
87 additions
and
9 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
31 changes: 31 additions & 0 deletions
31
packages/jest-did-matcher/src/matchers/toBeMultibaseString/index.js
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,31 @@ | ||
import { matcherHint, printExpected, printReceived } from 'jest-matcher-utils'; | ||
import predicate from './predicate'; | ||
|
||
const passMessage = received => () => | ||
matcherHint('.not.toBeMultibaseString', 'received', '') + | ||
'\n\n' + | ||
'Expected value to not be a Multibase string received:\n' + | ||
` ${printReceived(received)}`; | ||
|
||
const failMessage = received => () => | ||
matcherHint('.toBeMultibaseString', 'received', '') + | ||
'\n\n' + | ||
'Expected value to be a Multibase string:\n' + | ||
` ${printExpected('a Multibase string')}` + | ||
'Received:\n' + | ||
` ${printReceived(received)}`; | ||
|
||
export default { | ||
toBeMultibaseString: expected => { | ||
const pass = predicate(expected); | ||
if (pass) { | ||
return { pass: true, message: passMessage(expected) }; | ||
} | ||
|
||
return { pass: false, message: failMessage(expected) }; | ||
}, | ||
|
||
isMultibaseString: obj => { | ||
return predicate(obj); | ||
} | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/jest-did-matcher/src/matchers/toBeMultibaseString/index.test.js
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,31 @@ | ||
import each from 'jest-each'; | ||
|
||
import matcher from './'; | ||
|
||
expect.extend(matcher); | ||
|
||
describe('.toBeMultibaseString', () => { | ||
each([ | ||
["z98RNr73hGzPakwdrkjdk7BSn5Xd3ZbaVgJX122hqZAaMv19p"], | ||
]).test('passes when given the item is Multibase String', given => { | ||
expect(given).toBeMultibaseString(); | ||
}); | ||
}); | ||
|
||
describe('.not.toBeMultibaseString', () => { | ||
each([ | ||
[false], | ||
[""], | ||
["JKJKJK"], | ||
["5!@)"], | ||
[0], | ||
[{}], | ||
[[]], | ||
[() => {}], | ||
[null], | ||
[undefined], | ||
[NaN] | ||
]).test('passes when the item is not a Multibase String: %s', given => { | ||
expect(given).not.toBeMultibaseString(); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/jest-did-matcher/src/matchers/toBeMultibaseString/predicate.js
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,7 @@ | ||
export default expected => { | ||
const multibaseRegex = /^[079fFvVtTbBcChkKzZmMuUp].+$/; | ||
if (! (typeof expected === 'string' || expected instanceof String) ) { | ||
return false; | ||
} | ||
return multibaseRegex.test(expected); | ||
}; |