UNPKG

888 BJavaScriptView Raw
1import test from 'ava'
2import Chance from '../chance.js'
3import _ from 'lodash'
4
5const chance = new Chance()
6
7const timeout = (seconds) => {
8 new Promise((resolve, reject) => {
9 setTimeout(() => resolve(), seconds)
10 })
11}
12
13//chance.animal()
14
15test('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
25test('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
33test('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})