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

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.5 KB
Line 
1'use strict';
2
3var test = require('tape');
4
5var getSideChannel = require('../');
6
7test('getSideChannel', function (t) {
8 t.test('export', function (st) {
9 st.equal(typeof getSideChannel, 'function', 'is a function');
10
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 });
102
103 t.end();
104});
Note: See TracBrowser for help on using the repository browser.