call_tracker.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. /**
  6. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  7. *
  8. * This source code is licensed under the MIT license found in the
  9. * LICENSE file in the root directory of this source tree.
  10. *
  11. */
  12. // This file is a heavily modified fork of Jasmine. Original license:
  13. /*
  14. Copyright (c) 2008-2016 Pivotal Labs
  15. Permission is hereby granted, free of charge, to any person obtaining
  16. a copy of this software and associated documentation files (the
  17. "Software"), to deal in the Software without restriction, including
  18. without limitation the rights to use, copy, modify, merge, publish,
  19. distribute, sublicense, and/or sell copies of the Software, and to
  20. permit persons to whom the Software is furnished to do so, subject to
  21. the following conditions:
  22. The above copyright notice and this permission notice shall be
  23. included in all copies or substantial portions of the Software.
  24. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. */
  32. /* eslint-disable sort-keys */
  33. function CallTracker() {
  34. let calls = [];
  35. this.track = function(context) {
  36. calls.push(context);
  37. };
  38. this.any = function() {
  39. return !!calls.length;
  40. };
  41. this.count = function() {
  42. return calls.length;
  43. };
  44. this.argsFor = function(index) {
  45. const call = calls[index];
  46. return call ? call.args : [];
  47. };
  48. this.all = function() {
  49. return calls;
  50. };
  51. this.allArgs = function() {
  52. const callArgs = [];
  53. for (let i = 0; i < calls.length; i++) {
  54. callArgs.push(calls[i].args);
  55. }
  56. return callArgs;
  57. };
  58. this.first = function() {
  59. return calls[0];
  60. };
  61. this.mostRecent = function() {
  62. return calls[calls.length - 1];
  63. };
  64. this.reset = function() {
  65. calls = [];
  66. };
  67. }
  68. exports.default = CallTracker;