Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

SpyStrategy.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _defineProperty(obj, key, value) {
  7. if (key in obj) {
  8. Object.defineProperty(obj, key, {
  9. value: value,
  10. enumerable: true,
  11. configurable: true,
  12. writable: true
  13. });
  14. } else {
  15. obj[key] = value;
  16. }
  17. return obj;
  18. }
  19. /**
  20. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  21. *
  22. * This source code is licensed under the MIT license found in the
  23. * LICENSE file in the root directory of this source tree.
  24. *
  25. */
  26. // This file is a heavily modified fork of Jasmine. Original license:
  27. /*
  28. Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  29. Permission is hereby granted, free of charge, to any person obtaining
  30. a copy of this software and associated documentation files (the
  31. "Software"), to deal in the Software without restriction, including
  32. without limitation the rights to use, copy, modify, merge, publish,
  33. distribute, sublicense, and/or sell copies of the Software, and to
  34. permit persons to whom the Software is furnished to do so, subject to
  35. the following conditions:
  36. The above copyright notice and this permission notice shall be
  37. included in all copies or substantial portions of the Software.
  38. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  39. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  40. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  41. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  42. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  43. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  44. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  45. */
  46. /* eslint-disable local/ban-types-eventually, local/prefer-rest-params-eventually */
  47. class SpyStrategy {
  48. constructor({
  49. name = 'unknown',
  50. fn = function () {},
  51. getSpy = function () {}
  52. } = {}) {
  53. _defineProperty(this, 'identity', void 0);
  54. _defineProperty(this, 'exec', void 0);
  55. _defineProperty(this, 'callThrough', void 0);
  56. _defineProperty(this, 'returnValue', void 0);
  57. _defineProperty(this, 'returnValues', void 0);
  58. _defineProperty(this, 'throwError', void 0);
  59. _defineProperty(this, 'callFake', void 0);
  60. _defineProperty(this, 'stub', void 0);
  61. const identity = name;
  62. const originalFn = fn;
  63. let plan = function () {};
  64. this.identity = function () {
  65. return identity;
  66. };
  67. this.exec = function () {
  68. return plan.apply(this, arguments);
  69. };
  70. this.callThrough = function () {
  71. plan = originalFn;
  72. return getSpy();
  73. };
  74. this.returnValue = function (value) {
  75. plan = function () {
  76. return value;
  77. };
  78. return getSpy();
  79. };
  80. this.returnValues = function () {
  81. const values = Array.prototype.slice.call(arguments);
  82. plan = function () {
  83. return values.shift();
  84. };
  85. return getSpy();
  86. };
  87. this.throwError = function (something) {
  88. const error =
  89. something instanceof Error ? something : new Error(something);
  90. plan = function () {
  91. throw error;
  92. };
  93. return getSpy();
  94. };
  95. this.callFake = function (fn) {
  96. if (typeof fn !== 'function') {
  97. throw new Error(
  98. 'Argument passed to callFake should be a function, got ' + fn
  99. );
  100. }
  101. plan = fn;
  102. return getSpy();
  103. };
  104. this.stub = function (_fn) {
  105. plan = function () {};
  106. return getSpy();
  107. };
  108. }
  109. }
  110. exports.default = SpyStrategy;