|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.4 KB
|
| Line | |
|---|
| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | var assert = require("@sinonjs/referee-sinon").assert;
|
|---|
| 4 | var knuthShuffle = require("knuth-shuffle").knuthShuffle;
|
|---|
| 5 | var sinon = require("@sinonjs/referee-sinon").sinon;
|
|---|
| 6 | var orderByFirstCall = require("./order-by-first-call");
|
|---|
| 7 |
|
|---|
| 8 | describe("orderByFirstCall", function () {
|
|---|
| 9 | it("should order an Array of spies by the callId of the first call, ascending", function () {
|
|---|
| 10 | // create an array of spies
|
|---|
| 11 | var spies = [
|
|---|
| 12 | sinon.spy(),
|
|---|
| 13 | sinon.spy(),
|
|---|
| 14 | sinon.spy(),
|
|---|
| 15 | sinon.spy(),
|
|---|
| 16 | sinon.spy(),
|
|---|
| 17 | sinon.spy(),
|
|---|
| 18 | ];
|
|---|
| 19 |
|
|---|
| 20 | // call all the spies
|
|---|
| 21 | spies.forEach(function (spy) {
|
|---|
| 22 | spy();
|
|---|
| 23 | });
|
|---|
| 24 |
|
|---|
| 25 | // add a few uncalled spies
|
|---|
| 26 | spies.push(sinon.spy());
|
|---|
| 27 | spies.push(sinon.spy());
|
|---|
| 28 |
|
|---|
| 29 | // randomise the order of the spies
|
|---|
| 30 | knuthShuffle(spies);
|
|---|
| 31 |
|
|---|
| 32 | var sortedSpies = orderByFirstCall(spies);
|
|---|
| 33 |
|
|---|
| 34 | assert.equals(sortedSpies.length, spies.length);
|
|---|
| 35 |
|
|---|
| 36 | var orderedByFirstCall = sortedSpies.every(function (spy, index) {
|
|---|
| 37 | if (index + 1 === sortedSpies.length) {
|
|---|
| 38 | return true;
|
|---|
| 39 | }
|
|---|
| 40 | var nextSpy = sortedSpies[index + 1];
|
|---|
| 41 |
|
|---|
| 42 | // uncalled spies should be ordered first
|
|---|
| 43 | if (!spy.called) {
|
|---|
| 44 | return true;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | return spy.calledImmediatelyBefore(nextSpy);
|
|---|
| 48 | });
|
|---|
| 49 |
|
|---|
| 50 | assert.isTrue(orderedByFirstCall);
|
|---|
| 51 | });
|
|---|
| 52 | });
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.