1 | import test from 'ava'
|
2 | import Chance from '../chance.js'
|
3 | import _ from 'lodash'
|
4 |
|
5 | const chance = new Chance()
|
6 |
|
7 | const timeout = (seconds) => {
|
8 | new Promise((resolve, reject) => {
|
9 | setTimeout(() => resolve(), seconds)
|
10 | })
|
11 | }
|
12 |
|
13 |
|
14 |
|
15 | test('returns an animal', t => {
|
16 | _.times(1000, () => {
|
17 | let animal = chance.animal({
|
18 | type: "desert"
|
19 | })
|
20 | t.true(_.isString(animal))
|
21 | t.true(animal.length >= 2)
|
22 | })
|
23 | })
|
24 |
|
25 | test('returns an animal even if type is not specified', t => {
|
26 | _.times(1000, () => {
|
27 | let animal = chance.animal()
|
28 | t.true(_.isString(animal))
|
29 | t.true(animal.length >= 2)
|
30 | })
|
31 | })
|
32 |
|
33 | test('throws an error if the type is not part of the animals object', t => {
|
34 | _.times(1000, () => {
|
35 | const fn = () => chance.animal({
|
36 | type: "banana"
|
37 | })
|
38 | t.throws(fn, "Please pick from desert, ocean, grassland, forest, zoo, pets, farm.")
|
39 | })
|
40 | })
|