Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/side-channel/test/index.js
r0c6b92a r79a0317 5 5 var getSideChannel = require('../'); 6 6 7 test(' export', function (t) {8 t. equal(typeof getSideChannel, 'function', 'is a function');9 t.equal(getSideChannel.length, 0, 'takes no arguments');7 test('getSideChannel', function (t) { 8 t.test('export', function (st) { 9 st.equal(typeof getSideChannel, 'function', 'is a function'); 10 10 11 var channel = getSideChannel(); 12 t.ok(channel, 'is truthy'); 13 t.equal(typeof channel, 'object', 'is an object'); 11 st.equal(getSideChannel.length, 0, 'takes no arguments'); 12 13 var channel = getSideChannel(); 14 st.ok(channel, 'is truthy'); 15 st.equal(typeof channel, 'object', 'is an object'); 16 st.end(); 17 }); 18 19 t.test('assert', function (st) { 20 var channel = getSideChannel(); 21 st['throws']( 22 function () { channel.assert({}); }, 23 TypeError, 24 'nonexistent value throws' 25 ); 26 27 var o = {}; 28 channel.set(o, 'data'); 29 st.doesNotThrow(function () { channel.assert(o); }, 'existent value noops'); 30 31 st.end(); 32 }); 33 34 t.test('has', function (st) { 35 var channel = getSideChannel(); 36 /** @type {unknown[]} */ var o = []; 37 38 st.equal(channel.has(o), false, 'nonexistent value yields false'); 39 40 channel.set(o, 'foo'); 41 st.equal(channel.has(o), true, 'existent value yields true'); 42 43 st.equal(channel.has('abc'), false, 'non object value non existent yields false'); 44 45 channel.set('abc', 'foo'); 46 st.equal(channel.has('abc'), true, 'non object value that exists yields true'); 47 48 st.end(); 49 }); 50 51 t.test('get', function (st) { 52 var channel = getSideChannel(); 53 var o = {}; 54 st.equal(channel.get(o), undefined, 'nonexistent value yields undefined'); 55 56 var data = {}; 57 channel.set(o, data); 58 st.equal(channel.get(o), data, '"get" yields data set by "set"'); 59 60 st.end(); 61 }); 62 63 t.test('set', function (st) { 64 var channel = getSideChannel(); 65 var o = function () {}; 66 st.equal(channel.get(o), undefined, 'value not set'); 67 68 channel.set(o, 42); 69 st.equal(channel.get(o), 42, 'value was set'); 70 71 channel.set(o, Infinity); 72 st.equal(channel.get(o), Infinity, 'value was set again'); 73 74 var o2 = {}; 75 channel.set(o2, 17); 76 st.equal(channel.get(o), Infinity, 'o is not modified'); 77 st.equal(channel.get(o2), 17, 'o2 is set'); 78 79 channel.set(o, 14); 80 st.equal(channel.get(o), 14, 'o is modified'); 81 st.equal(channel.get(o2), 17, 'o2 is not modified'); 82 83 st.end(); 84 }); 85 86 t.test('delete', function (st) { 87 var channel = getSideChannel(); 88 var o = {}; 89 st.equal(channel['delete']({}), false, 'nonexistent value yields false'); 90 91 channel.set(o, 42); 92 st.equal(channel.has(o), true, 'value is set'); 93 94 st.equal(channel['delete']({}), false, 'nonexistent value still yields false'); 95 96 st.equal(channel['delete'](o), true, 'deleted value yields true'); 97 98 st.equal(channel.has(o), false, 'value is no longer set'); 99 100 st.end(); 101 }); 14 102 15 103 t.end(); 16 104 }); 17 18 test('assert', function (t) {19 var channel = getSideChannel();20 t['throws'](21 function () { channel.assert({}); },22 TypeError,23 'nonexistent value throws'24 );25 26 var o = {};27 channel.set(o, 'data');28 t.doesNotThrow(function () { channel.assert(o); }, 'existent value noops');29 30 t.end();31 });32 33 test('has', function (t) {34 var channel = getSideChannel();35 /** @type {unknown[]} */ var o = [];36 37 t.equal(channel.has(o), false, 'nonexistent value yields false');38 39 channel.set(o, 'foo');40 t.equal(channel.has(o), true, 'existent value yields true');41 42 t.equal(channel.has('abc'), false, 'non object value non existent yields false');43 44 channel.set('abc', 'foo');45 t.equal(channel.has('abc'), true, 'non object value that exists yields true');46 47 t.end();48 });49 50 test('get', function (t) {51 var channel = getSideChannel();52 var o = {};53 t.equal(channel.get(o), undefined, 'nonexistent value yields undefined');54 55 var data = {};56 channel.set(o, data);57 t.equal(channel.get(o), data, '"get" yields data set by "set"');58 59 t.end();60 });61 62 test('set', function (t) {63 var channel = getSideChannel();64 var o = function () {};65 t.equal(channel.get(o), undefined, 'value not set');66 67 channel.set(o, 42);68 t.equal(channel.get(o), 42, 'value was set');69 70 channel.set(o, Infinity);71 t.equal(channel.get(o), Infinity, 'value was set again');72 73 var o2 = {};74 channel.set(o2, 17);75 t.equal(channel.get(o), Infinity, 'o is not modified');76 t.equal(channel.get(o2), 17, 'o2 is set');77 78 channel.set(o, 14);79 t.equal(channel.get(o), 14, 'o is modified');80 t.equal(channel.get(o2), 17, 'o2 is not modified');81 82 t.end();83 });
Note:
See TracChangeset
for help on using the changeset viewer.