source: frontend/node_modules/@sinonjs/commons/lib/called-in-order.test.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.6 KB
Line 
1"use strict";
2
3var assert = require("@sinonjs/referee-sinon").assert;
4var calledInOrder = require("./called-in-order");
5var sinon = require("@sinonjs/referee-sinon").sinon;
6
7var testObject1 = {
8 someFunction: function () {
9 return;
10 },
11};
12var testObject2 = {
13 otherFunction: function () {
14 return;
15 },
16};
17var testObject3 = {
18 thirdFunction: function () {
19 return;
20 },
21};
22
23function testMethod() {
24 testObject1.someFunction();
25 testObject2.otherFunction();
26 testObject2.otherFunction();
27 testObject2.otherFunction();
28 testObject3.thirdFunction();
29}
30
31describe("calledInOrder", function () {
32 beforeEach(function () {
33 sinon.stub(testObject1, "someFunction");
34 sinon.stub(testObject2, "otherFunction");
35 sinon.stub(testObject3, "thirdFunction");
36 testMethod();
37 });
38 afterEach(function () {
39 testObject1.someFunction.restore();
40 testObject2.otherFunction.restore();
41 testObject3.thirdFunction.restore();
42 });
43
44 describe("given single array argument", function () {
45 describe("when stubs were called in expected order", function () {
46 it("returns true", function () {
47 assert.isTrue(
48 calledInOrder([
49 testObject1.someFunction,
50 testObject2.otherFunction,
51 ])
52 );
53 assert.isTrue(
54 calledInOrder([
55 testObject1.someFunction,
56 testObject2.otherFunction,
57 testObject2.otherFunction,
58 testObject3.thirdFunction,
59 ])
60 );
61 });
62 });
63
64 describe("when stubs were called in unexpected order", function () {
65 it("returns false", function () {
66 assert.isFalse(
67 calledInOrder([
68 testObject2.otherFunction,
69 testObject1.someFunction,
70 ])
71 );
72 assert.isFalse(
73 calledInOrder([
74 testObject2.otherFunction,
75 testObject1.someFunction,
76 testObject1.someFunction,
77 testObject3.thirdFunction,
78 ])
79 );
80 });
81 });
82 });
83
84 describe("given multiple arguments", function () {
85 describe("when stubs were called in expected order", function () {
86 it("returns true", function () {
87 assert.isTrue(
88 calledInOrder(
89 testObject1.someFunction,
90 testObject2.otherFunction
91 )
92 );
93 assert.isTrue(
94 calledInOrder(
95 testObject1.someFunction,
96 testObject2.otherFunction,
97 testObject3.thirdFunction
98 )
99 );
100 });
101 });
102
103 describe("when stubs were called in unexpected order", function () {
104 it("returns false", function () {
105 assert.isFalse(
106 calledInOrder(
107 testObject2.otherFunction,
108 testObject1.someFunction
109 )
110 );
111 assert.isFalse(
112 calledInOrder(
113 testObject2.otherFunction,
114 testObject1.someFunction,
115 testObject3.thirdFunction
116 )
117 );
118 });
119 });
120 });
121});
Note: See TracBrowser for help on using the repository browser.