Node-Red configuration
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

index.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use strict';
  2. var test = require('tape');
  3. var getSideChannel = require('../');
  4. test('export', function (t) {
  5. t.equal(typeof getSideChannel, 'function', 'is a function');
  6. t.equal(getSideChannel.length, 0, 'takes no arguments');
  7. var channel = getSideChannel();
  8. t.ok(channel, 'is truthy');
  9. t.equal(typeof channel, 'object', 'is an object');
  10. t.end();
  11. });
  12. test('assert', function (t) {
  13. var channel = getSideChannel();
  14. t['throws'](
  15. function () { channel.assert({}); },
  16. TypeError,
  17. 'nonexistent value throws'
  18. );
  19. var o = {};
  20. channel.set(o, 'data');
  21. t.doesNotThrow(function () { channel.assert(o); }, 'existent value noops');
  22. t.end();
  23. });
  24. test('has', function (t) {
  25. var channel = getSideChannel();
  26. /** @type {unknown[]} */ var o = [];
  27. t.equal(channel.has(o), false, 'nonexistent value yields false');
  28. channel.set(o, 'foo');
  29. t.equal(channel.has(o), true, 'existent value yields true');
  30. t.equal(channel.has('abc'), false, 'non object value non existent yields false');
  31. channel.set('abc', 'foo');
  32. t.equal(channel.has('abc'), true, 'non object value that exists yields true');
  33. t.end();
  34. });
  35. test('get', function (t) {
  36. var channel = getSideChannel();
  37. var o = {};
  38. t.equal(channel.get(o), undefined, 'nonexistent value yields undefined');
  39. var data = {};
  40. channel.set(o, data);
  41. t.equal(channel.get(o), data, '"get" yields data set by "set"');
  42. t.end();
  43. });
  44. test('set', function (t) {
  45. var channel = getSideChannel();
  46. var o = function () {};
  47. t.equal(channel.get(o), undefined, 'value not set');
  48. channel.set(o, 42);
  49. t.equal(channel.get(o), 42, 'value was set');
  50. channel.set(o, Infinity);
  51. t.equal(channel.get(o), Infinity, 'value was set again');
  52. var o2 = {};
  53. channel.set(o2, 17);
  54. t.equal(channel.get(o), Infinity, 'o is not modified');
  55. t.equal(channel.get(o2), 17, 'o2 is set');
  56. channel.set(o, 14);
  57. t.equal(channel.get(o), 14, 'o is modified');
  58. t.equal(channel.get(o2), 17, 'o2 is not modified');
  59. t.end();
  60. });