order-by-first-call.js 456 B

123456789101112131415161718
  1. "use strict";
  2. var sort = require("./prototypes/array").sort;
  3. var slice = require("./prototypes/array").slice;
  4. function comparator(a, b) {
  5. // uuid, won't ever be equal
  6. var aCall = a.getCall(0);
  7. var bCall = b.getCall(0);
  8. var aId = (aCall && aCall.callId) || -1;
  9. var bId = (bCall && bCall.callId) || -1;
  10. return aId < bId ? -1 : 1;
  11. }
  12. module.exports = function orderByFirstCall(spies) {
  13. return sort(slice(spies), comparator);
  14. };