-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
55b853b
commit 2e4e50f
Showing
10 changed files
with
112 additions
and
44 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,8 @@ | ||
{ | ||
"TEST_ANSWERS": [ | ||
"Yes", | ||
"No", | ||
"I'm not ready to give an answer", | ||
"Try again later" | ||
] | ||
} |
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 |
---|---|---|
@@ -1,16 +1,31 @@ | ||
import { getAnswer } from '../dist'; | ||
import { MagicBall } from '../dist'; | ||
import { DEFAULT_ANSWERS } from '../src/answers.json'; | ||
import { TEST_ANSWERS } from './test-answers.json'; | ||
|
||
describe('getAnswer method:', () => { | ||
test('type of received value', () => { | ||
const answer = getAnswer(); | ||
describe('MagicBall instance with default values:', () => { | ||
const magicBall = new MagicBall(); | ||
|
||
expect(typeof answer).toBe('string'); | ||
test('type of received value', () => { | ||
expect(typeof magicBall.getAnswer()).toBe('string'); | ||
}); | ||
|
||
test('default answers contain received value', () => { | ||
const answer = getAnswer(); | ||
expect(DEFAULT_ANSWERS.indexOf(magicBall.getAnswer())).toBeGreaterThanOrEqual(0); | ||
}); | ||
}); | ||
|
||
describe('MagicBall instance with custom values:', () => { | ||
const magicBall = new MagicBall(TEST_ANSWERS); | ||
|
||
test('type of received value', () => { | ||
expect(typeof magicBall.getAnswer()).toBe('string'); | ||
}); | ||
|
||
test('default answers does not contain received value', () => { | ||
expect(DEFAULT_ANSWERS.indexOf(magicBall.getAnswer())).toBeLessThan(0); | ||
}); | ||
|
||
expect(DEFAULT_ANSWERS.indexOf(answer)).toBeGreaterThanOrEqual(0); | ||
test('custom answers contain received value', () => { | ||
expect(TEST_ANSWERS.indexOf(magicBall.getAnswer())).toBeGreaterThanOrEqual(0); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import getAnswer from './magic-ball'; | ||
export { getAnswer }; | ||
import MagicBall from './magic-ball'; | ||
export { MagicBall }; | ||
declare const _default: { | ||
getAnswer: typeof getAnswer; | ||
MagicBall: typeof MagicBall; | ||
}; | ||
export default _default; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,12 +1,31 @@ | ||
/** | ||
* @description | ||
* Generates random answer. | ||
* @classdesc | ||
* Class creates random answers generator with custom or default answers | ||
* | ||
* @returns {string} | ||
* | ||
* @example | ||
* const answer = getAnswer(); | ||
* // => answer='It is decidedly so' | ||
**/ | ||
declare function getAnswer(): string; | ||
export default getAnswer; | ||
* - with default values: | ||
* const magicBall = new MagicBall(); | ||
* const answer = magicBall.getAnswer(); // => answer='It is decidedly so' | ||
* | ||
* - with custom values: | ||
* const magicBall = new MagicBall(['yes', 'no']); | ||
* const answer = magicBall.getAnswer(); // => answer='yes' | ||
*/ | ||
declare class MagicBall { | ||
#private; | ||
/** | ||
* Create a MagicBall | ||
* @param { string[] | undefined } answers - Sets the answers array, not mandatory. | ||
* If is not passed - will be used DEFAULT_ANSWERS array. | ||
*/ | ||
constructor(answers?: string[] | undefined); | ||
/** | ||
*@description | ||
* Generates the random answer | ||
* | ||
* @return {string} Random answer. | ||
*/ | ||
getAnswer: () => string; | ||
} | ||
export default MagicBall; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import getAnswer from './magic-ball'; | ||
import MagicBall from './magic-ball'; | ||
|
||
export { getAnswer }; | ||
export { MagicBall }; | ||
|
||
export default { getAnswer }; | ||
export default { MagicBall }; |
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