source: imaps-frontend/node_modules/side-channel/test/index.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.9 KB
Line 
1'use strict';
2
3var test = require('tape');
4
5var getSideChannel = require('../');
6
7test('export', function (t) {
8 t.equal(typeof getSideChannel, 'function', 'is a function');
9 t.equal(getSideChannel.length, 0, 'takes no arguments');
10
11 var channel = getSideChannel();
12 t.ok(channel, 'is truthy');
13 t.equal(typeof channel, 'object', 'is an object');
14
15 t.end();
16});
17
18test('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
33test('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
50test('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
62test('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 TracBrowser for help on using the repository browser.