UNPKG

1.42 kBJavaScriptView Raw
1var test = require('tape')
2var assertGiven = require('../assertGiven')
3
4test('throws when given is falsey', function (t) {
5 t.throws(() => assertGiven('cats'), /create function should return a function or an object/)
6 t.end()
7})
8
9test('ok when gives is a string and given is a function', function (t) {
10 t.doesNotThrow(() => assertGiven('cats', function () {}))
11 t.end()
12})
13
14test('throws when gives is a string but given is not a function', function (t) {
15 t.throws(() => assertGiven('cats', {}))
16 t.throws(() => assertGiven('cats', 'cats'))
17 t.end()
18})
19
20test('ok when gives is an object and given is an object with matching keys', function (t) {
21 var given = {
22 cats: function () {},
23 dogs: function () {}
24 }
25 var gives = {
26 cats: true,
27 dogs: true
28 }
29 t.doesNotThrow(() => assertGiven(gives, given))
30 t.end()
31})
32
33test('throws when gives is an object and given is an object with keys that do not match', function (t) {
34 var given = {
35 dogs: function () {}
36 }
37 var gives = {
38 cats: true,
39 dogs: true
40 }
41 t.throws(() => assertGiven(gives, given))
42 t.end()
43})
44
45test('throws when gives is a nested object and given is a nested object with keys that do not match', function (t) {
46 var given = {
47 animals: {
48 dogs: function () {}
49 }
50 }
51 var gives = {
52 animals: {
53 cats: true,
54 dogs: true
55 }
56 }
57 t.throws(() => assertGiven(gives, given))
58 t.end()
59})