|
1 | 1 | assert = require("assert")
|
2 |
| -Bacon = require("../bacon.matchers") |
| 2 | +Bacon = require("../bacon.matchers.js") # Test the result of the build |
3 | 3 |
|
4 | 4 | assertConstantly = (expectedValue, stream, done) ->
|
5 | 5 | stream.onValue (val) -> assert.equal expectedValue, val
|
@@ -75,4 +75,64 @@ describe 'bacon.matchers', ->
|
75 | 75 | it 'should return false with values not within range', (done) ->
|
76 | 76 | stream = Bacon.fromArray([6,20]).is().inClosedRange(7, 19)
|
77 | 77 | assertConstantly false, stream, done
|
78 |
| - |
| 78 | + describe 'containerOf', -> |
| 79 | + context 'value is an array', -> |
| 80 | + it 'should return true when the array contains the element', (done) -> |
| 81 | + stream = Bacon.once([6]).is().containerOf(6) |
| 82 | + assertConstantly true, stream, done |
| 83 | + it 'should return false when the array does not contain the element', (done) -> |
| 84 | + stream = Bacon.once([66]).is().containerOf(6) |
| 85 | + assertConstantly false, stream, done |
| 86 | + context 'value is a string', -> |
| 87 | + it 'should return true when the string contains the sub-string', (done) -> |
| 88 | + stream = Bacon.once('hello bacon').is().containerOf('bacon') |
| 89 | + assertConstantly true, stream, done |
| 90 | + it 'should return false when the string does not contain the sub-string', (done) -> |
| 91 | + stream = Bacon.once('hello bacon').is().containerOf('Bacon') |
| 92 | + assertConstantly false, stream, done |
| 93 | + context 'value is an object', -> |
| 94 | + it 'should return true when the object contains the key-value pair', (done) -> |
| 95 | + stream = Bacon.once({ |
| 96 | + alien: 'morninglightmountain' |
| 97 | + human: 'dudleybose' |
| 98 | + }).is().containerOf({alien: 'morninglightmountain'}) |
| 99 | + assertConstantly true, stream, done |
| 100 | + it 'should return true when comparing equal objects', (done) -> |
| 101 | + object = |
| 102 | + alien: 'morninglightmountain' |
| 103 | + stream = Bacon.once(object).is().containerOf(object) |
| 104 | + assertConstantly true, stream, done |
| 105 | + it 'should return false when key matches but value does not', (done) -> |
| 106 | + stream = Bacon.once( |
| 107 | + alien: 'morninglightmountain' |
| 108 | + ).is().containerOf(alien: 't1000') |
| 109 | + assertConstantly false, stream, done |
| 110 | + it 'should return false when the object contains a subset of the compared value', (done) -> |
| 111 | + stream = Bacon.once( |
| 112 | + alien: 'morninglightmountain' |
| 113 | + ).is().containerOf( |
| 114 | + alien: 'morninglightmountain' |
| 115 | + human: 'dudleybose' |
| 116 | + ) |
| 117 | + assertConstantly false, stream, done |
| 118 | + it 'should return false when comparing a non-empty object to {}', (done) -> |
| 119 | + stream = Bacon.once( |
| 120 | + alien: 'morninglightmountain' |
| 121 | + ).is().containerOf( {} ) |
| 122 | + assertConstantly false, stream, done |
| 123 | + it 'should return false when comparing {} to {}', (done) -> |
| 124 | + stream = Bacon.once( {} ).is().containerOf( {} ) |
| 125 | + assertConstantly false, stream, done |
| 126 | + context 'value is a boolean', -> |
| 127 | + it 'should always return false', (done) -> |
| 128 | + stream = Bacon.once(false).is().containerOf(false) |
| 129 | + assertConstantly false, stream, done |
| 130 | + context 'value is a number', -> |
| 131 | + it 'should always return false', (done) -> |
| 132 | + stream = Bacon.once(1).is().containerOf(1) |
| 133 | + assertConstantly false, stream, done |
| 134 | + context 'value is a function', -> |
| 135 | + it 'should always return false', (done) -> |
| 136 | + fun = -> |
| 137 | + stream = Bacon.once(fun).is().containerOf(fun) |
| 138 | + assertConstantly false, stream, done |
0 commit comments