用工小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.5 KiB

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