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