How to use testContext method in Cypress

Best JavaScript code snippet using cypress

scenario-proxies-unit-test.js

Source:scenario-proxies-unit-test.js Github

copy

Full Screen

1const Maddox = require('../../lib/index'), // require("maddox");2 random = require('../random'),3 constants = require('../../lib/constants'),4 Controller = require('../testable/modules/test-module/from-http-req-controller'),5 SpecialScenariosController = require('../testable/modules/test-module/special-scenarios-controller'),6 testConstants = require('../test-constants'),7 StatefulFactoryProxy = require('../testable/proxies/stateful-factory-proxy'),8 StatefulSingletonProxy = require('../testable/proxies/stateful-singleton-proxy'),9 StatelessEs6Proxy = require('../testable/proxies/stateless-es6-proxy'),10 StatelessPreEs6SingletonProxy = require('../testable/proxies/stateless-pre-es6-singleton-proxy'),11 StatelessPreEs6StaticProxy = require('../testable/proxies/stateless-pre-es6-static-proxy');12const Scenario = Maddox.functional.HttpReqScenario;13describe('Given a Scenario', function () {14 let testContext;15 describe('when without external dependencies, it', function () {16 beforeEach(function () {17 testContext = {};18 testContext.setupTest = function () {19 testContext.entryPointObject = Controller;20 testContext.entryPointFunction = 'noProxies';21 };22 testContext.setupHttpRequest = function () {23 testContext.httpRequest = {24 params: {25 personId: '123456789'26 },27 query: {28 homeState: 'IL'29 }30 };31 testContext.httpRequestParams = [testContext.httpRequest];32 };33 testContext.setupExpected = function () {34 testContext.expectedResponse = [{35 personId: testContext.httpRequest.params.personId,36 homeState: testContext.httpRequest.query.homeState37 }];38 testContext.expectedStatusCode = [200];39 };40 });41 it('should get expected result.', function (done) {42 testContext.setupTest();43 testContext.setupHttpRequest();44 testContext.setupExpected();45 new Scenario(this)46 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)47 .withHttpRequest(testContext.httpRequestParams)48 .resShouldBeCalledWith('send', testContext.expectedResponse)49 .resShouldBeCalledWith('status', testContext.expectedStatusCode)50 .resDoesReturnSelf('status')51 .test(done);52 });53 it('should handle a checked exception.', function (done) {54 testContext.setupHttpRequest = function () {55 testContext.httpRequest = {56 params: {},57 query: {58 homeState: 'IL'59 }60 };61 testContext.httpRequestParams = [testContext.httpRequest];62 };63 testContext.setupExpected = function () {64 testContext.expectedResponse = [testConstants.MissingPersonIdParam];65 testContext.expectedStatusCode = [404];66 };67 testContext.setupTest();68 testContext.setupHttpRequest();69 testContext.setupExpected();70 new Scenario(this)71 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)72 .withHttpRequest(testContext.httpRequestParams)73 .resShouldBeCalledWith('send', testContext.expectedResponse)74 .resShouldBeCalledWith('status', testContext.expectedStatusCode)75 .resDoesReturnSelf('status')76 .test(done);77 });78 });79 describe('when using a stateful factory proxy, it', function () {80 beforeEach(function () {81 testContext = {};82 testContext.setupTest = function () {83 testContext.entryPointObject = Controller;84 testContext.entryPointFunction = 'statefulFactoryProxy';85 testContext.proxyInstance = StatefulFactoryProxy.factory();86 };87 testContext.setupHttpRequest = function () {88 testContext.httpRequest = {89 params: {90 personId: '123456789'91 },92 query: {93 homeState: 'IL'94 }95 };96 testContext.httpRequestParams = [testContext.httpRequest];97 };98 testContext.setupGetFirstName = function () {99 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];100 testContext.getFirstName1Result = random.firstName();101 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];102 testContext.getFirstName2Result = random.firstName();103 };104 testContext.setupGetMiddleName = function () {105 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];106 testContext.getMiddleNameResult = random.firstName();107 };108 testContext.setupGetLastName = function () {109 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];110 testContext.getLastNameResult = [undefined, random.lastName()];111 };112 testContext.setupExpected = function () {113 testContext.expectedResponse = [{114 personId: testContext.httpRequest.params.personId,115 homeState: testContext.httpRequest.query.homeState,116 lastName: testContext.getLastNameResult[1]117 }];118 testContext.expectedStatusCode = [200];119 };120 });121 it('should pass all tests.', function (done) {122 testContext.setupTest();123 testContext.setupHttpRequest();124 testContext.setupGetFirstName();125 testContext.setupGetMiddleName();126 testContext.setupGetLastName();127 testContext.setupExpected();128 new Scenario(this)129 .mockThisFunction('StatefulFactoryProxy', 'factory', StatefulFactoryProxy)130 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)131 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)132 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)133 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)134 .withHttpRequest(testContext.httpRequestParams)135 .resShouldBeCalledWith('send', testContext.expectedResponse)136 .resShouldBeCalledWith('status', testContext.expectedStatusCode)137 .resDoesReturnSelf('status')138 .shouldBeCalledWith('StatefulFactoryProxy', 'factory', Maddox.constants.EmptyParameters)139 .doesReturn('StatefulFactoryProxy', 'factory', testContext.proxyInstance)140 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)141 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)142 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)143 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)144 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)145 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)146 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)147 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)148 .perf()149 .test(done);150 });151 it('should handle a checked exception.', function (done) {152 testContext.setupHttpRequest = function () {153 testContext.httpRequest = {154 params: {},155 query: {156 homeState: 'IL'157 }158 };159 testContext.httpRequestParams = [testContext.httpRequest];160 };161 testContext.setupExpected = function () {162 testContext.expectedResponse = [testConstants.MissingPersonIdParam];163 testContext.expectedStatusCode = [404];164 };165 testContext.setupTest();166 testContext.setupHttpRequest();167 testContext.setupGetFirstName();168 testContext.setupGetMiddleName();169 testContext.setupGetLastName();170 testContext.setupExpected();171 new Scenario(this)172 .mockThisFunction('StatefulFactoryProxy', 'factory', StatefulFactoryProxy)173 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)174 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)175 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)176 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)177 .withHttpRequest(testContext.httpRequestParams)178 .resShouldBeCalledWith('send', testContext.expectedResponse)179 .resShouldBeCalledWith('status', testContext.expectedStatusCode)180 .resDoesReturnSelf('status')181 .test(done);182 });183 it('should handle first call to mock throwing an error.', function (done) {184 testContext.setupGetFirstName = function () {185 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;186 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];187 testContext.getFirstName1Result = new Error(testContext.expectedErrorMessage);188 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];189 testContext.getFirstName2Result = random.firstName();190 };191 testContext.setupExpected = function () {192 testContext.expectedResponse = [testContext.expectedErrorMessage];193 testContext.expectedStatusCode = [404];194 };195 testContext.setupTest();196 testContext.setupHttpRequest();197 testContext.setupGetFirstName();198 testContext.setupGetMiddleName();199 testContext.setupGetLastName();200 testContext.setupExpected();201 new Scenario(this)202 .mockThisFunction('StatefulFactoryProxy', 'factory', StatefulFactoryProxy)203 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)204 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)205 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)206 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)207 .withHttpRequest(testContext.httpRequestParams)208 .resShouldBeCalledWith('send', testContext.expectedResponse)209 .resShouldBeCalledWith('status', testContext.expectedStatusCode)210 .resDoesReturnSelf('status')211 .shouldBeCalledWith('StatefulFactoryProxy', 'factory', Maddox.constants.EmptyParameters)212 .doesReturn('StatefulFactoryProxy', 'factory', testContext.proxyInstance)213 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)214 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)215 .test(done);216 });217 it('should handle second call to mock throwing an error.', function (done) {218 testContext.setupGetFirstName = function () {219 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;220 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];221 testContext.getFirstName1Result = random.firstName();222 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];223 testContext.getFirstName2Result = new Error(testContext.expectedErrorMessage);224 };225 testContext.setupExpected = function () {226 testContext.expectedResponse = [testContext.expectedErrorMessage];227 testContext.expectedStatusCode = [404];228 };229 testContext.setupTest();230 testContext.setupHttpRequest();231 testContext.setupGetFirstName();232 testContext.setupGetMiddleName();233 testContext.setupGetLastName();234 testContext.setupExpected();235 new Scenario(this)236 .mockThisFunction('StatefulFactoryProxy', 'factory', StatefulFactoryProxy)237 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)238 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)239 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)240 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)241 .withHttpRequest(testContext.httpRequestParams)242 .resShouldBeCalledWith('send', testContext.expectedResponse)243 .resShouldBeCalledWith('status', testContext.expectedStatusCode)244 .resDoesReturnSelf('status')245 .shouldBeCalledWith('StatefulFactoryProxy', 'factory', Maddox.constants.EmptyParameters)246 .doesReturn('StatefulFactoryProxy', 'factory', testContext.proxyInstance)247 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)248 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)249 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)250 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)251 .test(done);252 });253 it('should handle mock throwing an error with a promise.', function (done) {254 testContext.setupGetFirstName = function () {255 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;256 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];257 testContext.getFirstName1Result = new Error(testContext.expectedErrorMessage);258 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];259 testContext.getFirstName2Result = random.firstName();260 };261 testContext.setupExpected = function () {262 testContext.expectedResponse = [testContext.expectedErrorMessage];263 testContext.expectedStatusCode = [404];264 };265 testContext.setupTest();266 testContext.setupHttpRequest();267 testContext.setupGetFirstName();268 testContext.setupGetMiddleName();269 testContext.setupGetLastName();270 testContext.setupExpected();271 new Scenario(this)272 .mockThisFunction('StatefulFactoryProxy', 'factory', StatefulFactoryProxy)273 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)274 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)275 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)276 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)277 .withHttpRequest(testContext.httpRequestParams)278 .resShouldBeCalledWith('send', testContext.expectedResponse)279 .resShouldBeCalledWith('status', testContext.expectedStatusCode)280 .resDoesReturnSelf('status')281 .shouldBeCalledWith('StatefulFactoryProxy', 'factory', Maddox.constants.EmptyParameters)282 .doesReturn('StatefulFactoryProxy', 'factory', testContext.proxyInstance)283 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)284 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)285 .test(done);286 });287 it('should handle mock throwing an error with a callback.', function (done) {288 testContext.setupGetLastName = function () {289 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;290 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];291 testContext.getLastNameResult = [new Error(testContext.expectedErrorMessage)];292 };293 testContext.setupExpected = function () {294 testContext.expectedResponse = [testContext.expectedErrorMessage];295 testContext.expectedStatusCode = [404];296 };297 testContext.setupTest();298 testContext.setupHttpRequest();299 testContext.setupGetFirstName();300 testContext.setupGetMiddleName();301 testContext.setupGetLastName();302 testContext.setupExpected();303 new Scenario(this)304 .mockThisFunction('StatefulFactoryProxy', 'factory', StatefulFactoryProxy)305 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)306 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)307 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)308 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)309 .withHttpRequest(testContext.httpRequestParams)310 .resShouldBeCalledWith('send', testContext.expectedResponse)311 .resShouldBeCalledWith('status', testContext.expectedStatusCode)312 .resDoesReturnSelf('status')313 .shouldBeCalledWith('StatefulFactoryProxy', 'factory', Maddox.constants.EmptyParameters)314 .doesReturn('StatefulFactoryProxy', 'factory', testContext.proxyInstance)315 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)316 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)317 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)318 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)319 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)320 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)321 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)322 .doesErrorWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)323 .test(done).catch((err) => {324 done(err);325 });326 });327 it('should handle mock throwing an error synchronously.', function (done) {328 testContext.setupGetMiddleName = function () {329 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;330 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];331 testContext.getMiddleNameResult = new Error(testContext.expectedErrorMessage);332 };333 testContext.setupExpected = function () {334 testContext.expectedResponse = [testContext.expectedErrorMessage];335 testContext.expectedStatusCode = [404];336 };337 testContext.setupTest();338 testContext.setupHttpRequest();339 testContext.setupGetFirstName();340 testContext.setupGetMiddleName();341 testContext.setupGetLastName();342 testContext.setupExpected();343 new Scenario(this)344 .mockThisFunction('StatefulFactoryProxy', 'factory', StatefulFactoryProxy)345 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)346 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)347 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)348 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)349 .withHttpRequest(testContext.httpRequestParams)350 .resShouldBeCalledWith('send', testContext.expectedResponse)351 .resShouldBeCalledWith('status', testContext.expectedStatusCode)352 .resDoesReturnSelf('status')353 .shouldBeCalledWith('StatefulFactoryProxy', 'factory', Maddox.constants.EmptyParameters)354 .doesReturn('StatefulFactoryProxy', 'factory', testContext.proxyInstance)355 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)356 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)357 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)358 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)359 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)360 .doesError('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)361 .test(done).catch((err) => {362 done(err);363 });364 });365 });366 describe('when using a stateful singleton proxy, it', function () {367 beforeEach(function () {368 testContext = {};369 testContext.setupTest = function () {370 testContext.entryPointObject = Controller;371 testContext.entryPointFunction = 'statefulSingletonProxy';372 testContext.proxyInstance = StatefulSingletonProxy.getInstance();373 };374 testContext.setupHttpRequest = function () {375 testContext.httpRequest = {376 params: {377 personId: '123456789'378 },379 query: {380 homeState: 'IL'381 }382 };383 testContext.httpRequestParams = [testContext.httpRequest];384 };385 testContext.setupGetFirstName = function () {386 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];387 testContext.getFirstName1Result = random.firstName();388 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];389 testContext.getFirstName2Result = random.firstName();390 };391 testContext.setupGetMiddleName = function () {392 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];393 testContext.getMiddleNameResult = random.firstName();394 };395 testContext.setupGetLastName = function () {396 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];397 testContext.getLastNameResult = [undefined, random.lastName()];398 };399 testContext.setupExpected = function () {400 testContext.expectedResponse = [{401 personId: testContext.httpRequest.params.personId,402 homeState: testContext.httpRequest.query.homeState,403 lastName: testContext.getLastNameResult[1]404 }];405 testContext.expectedStatusCode = [200];406 };407 });408 it('should pass all tests.', function (done) {409 testContext.setupTest();410 testContext.setupHttpRequest();411 testContext.setupGetFirstName();412 testContext.setupGetMiddleName();413 testContext.setupGetLastName();414 testContext.setupExpected();415 new Scenario(this)416 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)417 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)418 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)419 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)420 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)421 .withHttpRequest(testContext.httpRequestParams)422 .resShouldBeCalledWith('send', testContext.expectedResponse)423 .resShouldBeCalledWith('status', testContext.expectedStatusCode)424 .resDoesReturnSelf('status')425 .shouldBeCalledWith('StatefulSingletonProxy', 'getInstance', Maddox.constants.EmptyParameters)426 .doesReturn('StatefulSingletonProxy', 'getInstance', testContext.proxyInstance)427 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)428 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)429 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)430 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)431 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)432 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)433 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)434 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)435 .perf()436 .test(done);437 });438 it('should handle a checked exception.', function (done) {439 testContext.setupHttpRequest = function () {440 testContext.httpRequest = {441 params: {},442 query: {443 homeState: 'IL'444 }445 };446 testContext.httpRequestParams = [testContext.httpRequest];447 };448 testContext.setupExpected = function () {449 testContext.expectedResponse = [testConstants.MissingPersonIdParam];450 testContext.expectedStatusCode = [404];451 };452 testContext.setupTest();453 testContext.setupHttpRequest();454 testContext.setupGetFirstName();455 testContext.setupGetMiddleName();456 testContext.setupGetLastName();457 testContext.setupExpected();458 new Scenario(this)459 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)460 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)461 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)462 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)463 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)464 .withHttpRequest(testContext.httpRequestParams)465 .resShouldBeCalledWith('send', testContext.expectedResponse)466 .resShouldBeCalledWith('status', testContext.expectedStatusCode)467 .resDoesReturnSelf('status')468 .test(done);469 });470 it('should handle first call to mock throwing an error.', function (done) {471 testContext.setupGetFirstName = function () {472 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;473 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];474 testContext.getFirstName1Result = new Error(testContext.expectedErrorMessage);475 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];476 testContext.getFirstName2Result = random.firstName();477 };478 testContext.setupExpected = function () {479 testContext.expectedResponse = [testContext.expectedErrorMessage];480 testContext.expectedStatusCode = [404];481 };482 testContext.setupTest();483 testContext.setupHttpRequest();484 testContext.setupGetFirstName();485 testContext.setupGetMiddleName();486 testContext.setupGetLastName();487 testContext.setupExpected();488 new Scenario(this)489 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)490 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)491 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)492 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)493 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)494 .withHttpRequest(testContext.httpRequestParams)495 .resShouldBeCalledWith('send', testContext.expectedResponse)496 .resShouldBeCalledWith('status', testContext.expectedStatusCode)497 .resDoesReturnSelf('status')498 .shouldBeCalledWith('StatefulSingletonProxy', 'getInstance', Maddox.constants.EmptyParameters)499 .doesReturn('StatefulSingletonProxy', 'getInstance', testContext.proxyInstance)500 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)501 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)502 .test(done);503 });504 it('should handle second call to mock throwing an error.', function (done) {505 testContext.setupGetFirstName = function () {506 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;507 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];508 testContext.getFirstName1Result = random.firstName();509 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];510 testContext.getFirstName2Result = new Error(testContext.expectedErrorMessage);511 };512 testContext.setupExpected = function () {513 testContext.expectedResponse = [testContext.expectedErrorMessage];514 testContext.expectedStatusCode = [404];515 };516 testContext.setupTest();517 testContext.setupHttpRequest();518 testContext.setupGetFirstName();519 testContext.setupGetMiddleName();520 testContext.setupGetLastName();521 testContext.setupExpected();522 new Scenario(this)523 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)524 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)525 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)526 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)527 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)528 .withHttpRequest(testContext.httpRequestParams)529 .resShouldBeCalledWith('send', testContext.expectedResponse)530 .resShouldBeCalledWith('status', testContext.expectedStatusCode)531 .resDoesReturnSelf('status')532 .shouldBeCalledWith('StatefulSingletonProxy', 'getInstance', Maddox.constants.EmptyParameters)533 .doesReturn('StatefulSingletonProxy', 'getInstance', testContext.proxyInstance)534 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)535 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)536 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)537 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)538 .test(done);539 });540 it('should handle mock throwing an error with a promise.', function (done) {541 testContext.setupGetFirstName = function () {542 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;543 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];544 testContext.getFirstName1Result = new Error(testContext.expectedErrorMessage);545 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];546 testContext.getFirstName2Result = random.firstName();547 };548 testContext.setupExpected = function () {549 testContext.expectedResponse = [testContext.expectedErrorMessage];550 testContext.expectedStatusCode = [404];551 };552 testContext.setupTest();553 testContext.setupHttpRequest();554 testContext.setupGetFirstName();555 testContext.setupGetMiddleName();556 testContext.setupGetLastName();557 testContext.setupExpected();558 new Scenario(this)559 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)560 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)561 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)562 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)563 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)564 .withHttpRequest(testContext.httpRequestParams)565 .resShouldBeCalledWith('send', testContext.expectedResponse)566 .resShouldBeCalledWith('status', testContext.expectedStatusCode)567 .resDoesReturnSelf('status')568 .shouldBeCalledWith('StatefulSingletonProxy', 'getInstance', Maddox.constants.EmptyParameters)569 .doesReturn('StatefulSingletonProxy', 'getInstance', testContext.proxyInstance)570 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)571 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)572 .test(done);573 });574 it('should handle mock throwing an error with a callback.', function (done) {575 testContext.setupGetLastName = function () {576 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;577 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];578 testContext.getLastNameResult = [new Error(testContext.expectedErrorMessage)];579 };580 testContext.setupExpected = function () {581 testContext.expectedResponse = [testContext.expectedErrorMessage];582 testContext.expectedStatusCode = [404];583 };584 testContext.setupTest();585 testContext.setupHttpRequest();586 testContext.setupGetFirstName();587 testContext.setupGetMiddleName();588 testContext.setupGetLastName();589 testContext.setupExpected();590 new Scenario(this)591 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)592 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)593 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)594 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)595 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)596 .withHttpRequest(testContext.httpRequestParams)597 .resShouldBeCalledWith('send', testContext.expectedResponse)598 .resShouldBeCalledWith('status', testContext.expectedStatusCode)599 .resDoesReturnSelf('status')600 .shouldBeCalledWith('StatefulSingletonProxy', 'getInstance', Maddox.constants.EmptyParameters)601 .doesReturn('StatefulSingletonProxy', 'getInstance', testContext.proxyInstance)602 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)603 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)604 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)605 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)606 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)607 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)608 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)609 .doesErrorWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)610 .test(done);611 });612 it('should handle mock throwing an error synchronously.', function (done) {613 testContext.setupGetMiddleName = function () {614 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;615 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];616 testContext.getMiddleNameResult = new Error(testContext.expectedErrorMessage);617 };618 testContext.setupExpected = function () {619 testContext.expectedResponse = [testContext.expectedErrorMessage];620 testContext.expectedStatusCode = [404];621 };622 testContext.setupTest();623 testContext.setupHttpRequest();624 testContext.setupGetFirstName();625 testContext.setupGetMiddleName();626 testContext.setupGetLastName();627 testContext.setupExpected();628 new Scenario(this)629 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)630 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)631 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)632 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)633 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)634 .withHttpRequest(testContext.httpRequestParams)635 .resShouldBeCalledWith('send', testContext.expectedResponse)636 .resShouldBeCalledWith('status', testContext.expectedStatusCode)637 .resDoesReturnSelf('status')638 .shouldBeCalledWith('StatefulSingletonProxy', 'getInstance', Maddox.constants.EmptyParameters)639 .doesReturn('StatefulSingletonProxy', 'getInstance', testContext.proxyInstance)640 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)641 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)642 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)643 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)644 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)645 .doesError('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)646 .test(done);647 });648 });649 describe('when using a stateless es6 proxy, it', function () {650 beforeEach(function () {651 testContext = {};652 testContext.setupTest = function () {653 testContext.entryPointObject = Controller;654 testContext.entryPointFunction = 'statelessEs6Proxy';655 testContext.proxyInstance = StatelessEs6Proxy;656 };657 testContext.setupHttpRequest = function () {658 testContext.httpRequest = {659 params: {660 personId: '123456789'661 },662 query: {663 homeState: 'IL'664 }665 };666 testContext.httpRequestParams = [testContext.httpRequest];667 };668 testContext.setupGetFirstName = function () {669 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];670 testContext.getFirstName1Result = random.firstName();671 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];672 testContext.getFirstName2Result = random.firstName();673 };674 testContext.setupGetMiddleName = function () {675 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];676 testContext.getMiddleNameResult = random.firstName();677 };678 testContext.setupGetLastName = function () {679 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];680 testContext.getLastNameResult = [undefined, random.lastName()];681 };682 testContext.setupExpected = function () {683 testContext.expectedResponse = [{684 personId: testContext.httpRequest.params.personId,685 homeState: testContext.httpRequest.query.homeState,686 lastName: testContext.getLastNameResult[1]687 }];688 testContext.expectedStatusCode = [200];689 };690 });691 it('should pass all tests.', function (done) {692 testContext.setupTest();693 testContext.setupHttpRequest();694 testContext.setupGetFirstName();695 testContext.setupGetMiddleName();696 testContext.setupGetLastName();697 testContext.setupExpected();698 new Scenario(this)699 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)700 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)701 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)702 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)703 .withHttpRequest(testContext.httpRequestParams)704 .resShouldBeCalledWith('send', testContext.expectedResponse)705 .resShouldBeCalledWith('status', testContext.expectedStatusCode)706 .resDoesReturnSelf('status')707 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)708 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)709 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)710 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)711 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)712 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)713 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)714 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)715 .perf()716 .test(done);717 });718 it('should handle a checked exception.', function (done) {719 testContext.setupHttpRequest = function () {720 testContext.httpRequest = {721 params: {},722 query: {723 homeState: 'IL'724 }725 };726 testContext.httpRequestParams = [testContext.httpRequest];727 };728 testContext.setupExpected = function () {729 testContext.expectedResponse = [testConstants.MissingPersonIdParam];730 testContext.expectedStatusCode = [404];731 };732 testContext.setupTest();733 testContext.setupHttpRequest();734 testContext.setupGetFirstName();735 testContext.setupGetMiddleName();736 testContext.setupGetLastName();737 testContext.setupExpected();738 new Scenario(this)739 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)740 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)741 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)742 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)743 .withHttpRequest(testContext.httpRequestParams)744 .resShouldBeCalledWith('send', testContext.expectedResponse)745 .resShouldBeCalledWith('status', testContext.expectedStatusCode)746 .resDoesReturnSelf('status')747 .test(done);748 });749 it('should handle first call to mock throwing an error.', function (done) {750 testContext.setupGetFirstName = function () {751 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;752 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];753 testContext.getFirstName1Result = new Error(testContext.expectedErrorMessage);754 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];755 testContext.getFirstName2Result = random.firstName();756 };757 testContext.setupExpected = function () {758 testContext.expectedResponse = [testContext.expectedErrorMessage];759 testContext.expectedStatusCode = [404];760 };761 testContext.setupTest();762 testContext.setupHttpRequest();763 testContext.setupGetFirstName();764 testContext.setupGetMiddleName();765 testContext.setupGetLastName();766 testContext.setupExpected();767 new Scenario(this)768 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)769 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)770 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)771 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)772 .withHttpRequest(testContext.httpRequestParams)773 .resShouldBeCalledWith('send', testContext.expectedResponse)774 .resShouldBeCalledWith('status', testContext.expectedStatusCode)775 .resDoesReturnSelf('status')776 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)777 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)778 .test(done);779 });780 it('should handle second call to mock throwing an error.', function (done) {781 testContext.setupGetFirstName = function () {782 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;783 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];784 testContext.getFirstName1Result = random.firstName();785 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];786 testContext.getFirstName2Result = new Error(testContext.expectedErrorMessage);787 };788 testContext.setupExpected = function () {789 testContext.expectedResponse = [testContext.expectedErrorMessage];790 testContext.expectedStatusCode = [404];791 };792 testContext.setupTest();793 testContext.setupHttpRequest();794 testContext.setupGetFirstName();795 testContext.setupGetMiddleName();796 testContext.setupGetLastName();797 testContext.setupExpected();798 new Scenario(this)799 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)800 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)801 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)802 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)803 .withHttpRequest(testContext.httpRequestParams)804 .resShouldBeCalledWith('send', testContext.expectedResponse)805 .resShouldBeCalledWith('status', testContext.expectedStatusCode)806 .resDoesReturnSelf('status')807 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)808 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)809 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)810 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)811 .test(done);812 });813 it('should handle mock throwing an error with a promise.', function (done) {814 testContext.setupGetFirstName = function () {815 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;816 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];817 testContext.getFirstName1Result = new Error(testContext.expectedErrorMessage);818 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];819 testContext.getFirstName2Result = random.firstName();820 };821 testContext.setupExpected = function () {822 testContext.expectedResponse = [testContext.expectedErrorMessage];823 testContext.expectedStatusCode = [404];824 };825 testContext.setupTest();826 testContext.setupHttpRequest();827 testContext.setupGetFirstName();828 testContext.setupGetMiddleName();829 testContext.setupGetLastName();830 testContext.setupExpected();831 new Scenario(this)832 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)833 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)834 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)835 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)836 .withHttpRequest(testContext.httpRequestParams)837 .resShouldBeCalledWith('send', testContext.expectedResponse)838 .resShouldBeCalledWith('status', testContext.expectedStatusCode)839 .resDoesReturnSelf('status')840 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)841 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)842 .test(done);843 });844 it('should handle mock throwing an error with a callback.', function (done) {845 testContext.setupGetLastName = function () {846 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;847 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];848 testContext.getLastNameResult = [new Error(testContext.expectedErrorMessage)];849 };850 testContext.setupExpected = function () {851 testContext.expectedResponse = [testContext.expectedErrorMessage];852 testContext.expectedStatusCode = [404];853 };854 testContext.setupTest();855 testContext.setupHttpRequest();856 testContext.setupGetFirstName();857 testContext.setupGetMiddleName();858 testContext.setupGetLastName();859 testContext.setupExpected();860 new Scenario(this)861 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)862 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)863 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)864 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)865 .withHttpRequest(testContext.httpRequestParams)866 .resShouldBeCalledWith('send', testContext.expectedResponse)867 .resShouldBeCalledWith('status', testContext.expectedStatusCode)868 .resDoesReturnSelf('status')869 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)870 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)871 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)872 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)873 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)874 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)875 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)876 .doesErrorWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)877 .test(done);878 });879 it('should handle mock throwing an error synchronously.', function (done) {880 testContext.setupGetMiddleName = function () {881 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;882 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];883 testContext.getMiddleNameResult = new Error(testContext.expectedErrorMessage);884 };885 testContext.setupExpected = function () {886 testContext.expectedResponse = [testContext.expectedErrorMessage];887 testContext.expectedStatusCode = [404];888 };889 testContext.setupTest();890 testContext.setupHttpRequest();891 testContext.setupGetFirstName();892 testContext.setupGetMiddleName();893 testContext.setupGetLastName();894 testContext.setupExpected();895 new Scenario(this)896 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)897 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)898 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)899 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)900 .withHttpRequest(testContext.httpRequestParams)901 .resShouldBeCalledWith('send', testContext.expectedResponse)902 .resShouldBeCalledWith('status', testContext.expectedStatusCode)903 .resDoesReturnSelf('status')904 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)905 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)906 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)907 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)908 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)909 .doesError('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)910 .test(done);911 });912 });913 describe('when using a stateless pre es6 singleton proxy, it', function () {914 beforeEach(function () {915 testContext = {};916 testContext.setupTest = function () {917 testContext.entryPointObject = Controller;918 testContext.entryPointFunction = 'statelessPreEs6SingletonProxy';919 testContext.proxyInstance = StatelessPreEs6SingletonProxy;920 };921 testContext.setupHttpRequest = function () {922 testContext.httpRequest = {923 params: {924 personId: '123456789'925 },926 query: {927 homeState: 'IL'928 }929 };930 testContext.httpRequestParams = [testContext.httpRequest];931 };932 testContext.setupGetFirstName = function () {933 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];934 testContext.getFirstName1Result = random.firstName();935 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];936 testContext.getFirstName2Result = random.firstName();937 };938 testContext.setupGetMiddleName = function () {939 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];940 testContext.getMiddleNameResult = random.firstName();941 };942 testContext.setupGetLastName = function () {943 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];944 testContext.getLastNameResult = [undefined, random.lastName()];945 };946 testContext.setupExpected = function () {947 testContext.expectedResponse = [{948 personId: testContext.httpRequest.params.personId,949 homeState: testContext.httpRequest.query.homeState,950 lastName: testContext.getLastNameResult[1]951 }];952 testContext.expectedStatusCode = [200];953 };954 });955 it('should pass all tests.', function (done) {956 testContext.setupTest();957 testContext.setupHttpRequest();958 testContext.setupGetFirstName();959 testContext.setupGetMiddleName();960 testContext.setupGetLastName();961 testContext.setupExpected();962 new Scenario(this)963 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)964 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)965 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)966 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)967 .withHttpRequest(testContext.httpRequestParams)968 .resShouldBeCalledWith('send', testContext.expectedResponse)969 .resShouldBeCalledWith('status', testContext.expectedStatusCode)970 .resDoesReturnSelf('status')971 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)972 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)973 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)974 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)975 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)976 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)977 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)978 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)979 .perf()980 .test(done);981 });982 it('should handle a checked exception.', function (done) {983 testContext.setupHttpRequest = function () {984 testContext.httpRequest = {985 params: {},986 query: {987 homeState: 'IL'988 }989 };990 testContext.httpRequestParams = [testContext.httpRequest];991 };992 testContext.setupExpected = function () {993 testContext.expectedResponse = [testConstants.MissingPersonIdParam];994 testContext.expectedStatusCode = [404];995 };996 testContext.setupTest();997 testContext.setupHttpRequest();998 testContext.setupGetFirstName();999 testContext.setupGetMiddleName();1000 testContext.setupGetLastName();1001 testContext.setupExpected();1002 new Scenario(this)1003 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1004 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1005 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1006 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1007 .withHttpRequest(testContext.httpRequestParams)1008 .resShouldBeCalledWith('send', testContext.expectedResponse)1009 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1010 .resDoesReturnSelf('status')1011 .test(done);1012 });1013 it('should handle first call to mock throwing an error.', function (done) {1014 testContext.setupGetFirstName = function () {1015 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;1016 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];1017 testContext.getFirstName1Result = new Error(testContext.expectedErrorMessage);1018 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1019 testContext.getFirstName2Result = random.firstName();1020 };1021 testContext.setupExpected = function () {1022 testContext.expectedResponse = [testContext.expectedErrorMessage];1023 testContext.expectedStatusCode = [404];1024 };1025 testContext.setupTest();1026 testContext.setupHttpRequest();1027 testContext.setupGetFirstName();1028 testContext.setupGetMiddleName();1029 testContext.setupGetLastName();1030 testContext.setupExpected();1031 new Scenario(this)1032 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1033 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1034 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1035 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1036 .withHttpRequest(testContext.httpRequestParams)1037 .resShouldBeCalledWith('send', testContext.expectedResponse)1038 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1039 .resDoesReturnSelf('status')1040 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1041 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1042 .test(done);1043 });1044 it('should handle second call to mock throwing an error.', function (done) {1045 testContext.setupGetFirstName = function () {1046 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;1047 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];1048 testContext.getFirstName1Result = random.firstName();1049 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1050 testContext.getFirstName2Result = new Error(testContext.expectedErrorMessage);1051 };1052 testContext.setupExpected = function () {1053 testContext.expectedResponse = [testContext.expectedErrorMessage];1054 testContext.expectedStatusCode = [404];1055 };1056 testContext.setupTest();1057 testContext.setupHttpRequest();1058 testContext.setupGetFirstName();1059 testContext.setupGetMiddleName();1060 testContext.setupGetLastName();1061 testContext.setupExpected();1062 new Scenario(this)1063 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1064 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1065 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1066 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1067 .withHttpRequest(testContext.httpRequestParams)1068 .resShouldBeCalledWith('send', testContext.expectedResponse)1069 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1070 .resDoesReturnSelf('status')1071 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1072 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1073 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)1074 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)1075 .test(done);1076 });1077 it('should handle mock throwing an error with a promise.', function (done) {1078 testContext.setupGetFirstName = function () {1079 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;1080 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];1081 testContext.getFirstName1Result = new Error(testContext.expectedErrorMessage);1082 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1083 testContext.getFirstName2Result = random.firstName();1084 };1085 testContext.setupExpected = function () {1086 testContext.expectedResponse = [testContext.expectedErrorMessage];1087 testContext.expectedStatusCode = [404];1088 };1089 testContext.setupTest();1090 testContext.setupHttpRequest();1091 testContext.setupGetFirstName();1092 testContext.setupGetMiddleName();1093 testContext.setupGetLastName();1094 testContext.setupExpected();1095 new Scenario(this)1096 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1097 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1098 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1099 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1100 .withHttpRequest(testContext.httpRequestParams)1101 .resShouldBeCalledWith('send', testContext.expectedResponse)1102 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1103 .resDoesReturnSelf('status')1104 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1105 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1106 .test(done);1107 });1108 it('should handle mock throwing an error with a callback.', function (done) {1109 testContext.setupGetLastName = function () {1110 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;1111 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];1112 testContext.getLastNameResult = [new Error(testContext.expectedErrorMessage)];1113 };1114 testContext.setupExpected = function () {1115 testContext.expectedResponse = [testContext.expectedErrorMessage];1116 testContext.expectedStatusCode = [404];1117 };1118 testContext.setupTest();1119 testContext.setupHttpRequest();1120 testContext.setupGetFirstName();1121 testContext.setupGetMiddleName();1122 testContext.setupGetLastName();1123 testContext.setupExpected();1124 new Scenario(this)1125 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1126 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1127 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1128 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1129 .withHttpRequest(testContext.httpRequestParams)1130 .resShouldBeCalledWith('send', testContext.expectedResponse)1131 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1132 .resDoesReturnSelf('status')1133 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1134 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1135 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)1136 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)1137 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)1138 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)1139 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)1140 .doesErrorWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)1141 .test(done);1142 });1143 it('should handle mock throwing an error synchronously.', function (done) {1144 testContext.setupGetMiddleName = function () {1145 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;1146 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];1147 testContext.getMiddleNameResult = new Error(testContext.expectedErrorMessage);1148 };1149 testContext.setupExpected = function () {1150 testContext.expectedResponse = [testContext.expectedErrorMessage];1151 testContext.expectedStatusCode = [404];1152 };1153 testContext.setupTest();1154 testContext.setupHttpRequest();1155 testContext.setupGetFirstName();1156 testContext.setupGetMiddleName();1157 testContext.setupGetLastName();1158 testContext.setupExpected();1159 new Scenario(this)1160 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1161 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1162 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1163 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1164 .withHttpRequest(testContext.httpRequestParams)1165 .resShouldBeCalledWith('send', testContext.expectedResponse)1166 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1167 .resDoesReturnSelf('status')1168 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1169 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1170 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)1171 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)1172 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)1173 .doesError('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)1174 .test(done);1175 });1176 });1177 describe('when using a stateless pre es6 static proxy, it', function () {1178 beforeEach(function () {1179 testContext = {};1180 testContext.setupTest = function () {1181 testContext.entryPointObject = Controller;1182 testContext.entryPointFunction = 'statelessPreEs6StaticProxy';1183 testContext.proxyInstance = StatelessPreEs6StaticProxy;1184 };1185 testContext.setupHttpRequest = function () {1186 testContext.httpRequest = {1187 params: {1188 personId: '123456789'1189 },1190 query: {1191 homeState: 'IL'1192 }1193 };1194 testContext.httpRequestParams = [testContext.httpRequest];1195 };1196 testContext.setupGetFirstName = function () {1197 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];1198 testContext.getFirstName1Result = random.firstName();1199 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1200 testContext.getFirstName2Result = random.firstName();1201 };1202 testContext.setupGetMiddleName = function () {1203 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];1204 testContext.getMiddleNameResult = random.firstName();1205 };1206 testContext.setupGetLastName = function () {1207 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];1208 testContext.getLastNameResult = [undefined, random.lastName()];1209 };1210 testContext.setupExpected = function () {1211 testContext.expectedResponse = [{1212 personId: testContext.httpRequest.params.personId,1213 homeState: testContext.httpRequest.query.homeState,1214 lastName: testContext.getLastNameResult[1]1215 }];1216 testContext.expectedStatusCode = [200];1217 };1218 });1219 it('should pass all tests.', function (done) {1220 testContext.setupTest();1221 testContext.setupHttpRequest();1222 testContext.setupGetFirstName();1223 testContext.setupGetMiddleName();1224 testContext.setupGetLastName();1225 testContext.setupExpected();1226 new Scenario(this)1227 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1228 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1229 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1230 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1231 .withHttpRequest(testContext.httpRequestParams)1232 .resShouldBeCalledWith('send', testContext.expectedResponse)1233 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1234 .resDoesReturnSelf('status')1235 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1236 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1237 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)1238 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)1239 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)1240 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)1241 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)1242 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)1243 .perf()1244 .test(done);1245 });1246 it('should handle a checked exception.', function (done) {1247 testContext.setupHttpRequest = function () {1248 testContext.httpRequest = {1249 params: {},1250 query: {1251 homeState: 'IL'1252 }1253 };1254 testContext.httpRequestParams = [testContext.httpRequest];1255 };1256 testContext.setupExpected = function () {1257 testContext.expectedResponse = [testConstants.MissingPersonIdParam];1258 testContext.expectedStatusCode = [404];1259 };1260 testContext.setupTest();1261 testContext.setupHttpRequest();1262 testContext.setupGetFirstName();1263 testContext.setupGetMiddleName();1264 testContext.setupGetLastName();1265 testContext.setupExpected();1266 new Scenario(this)1267 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1268 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1269 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1270 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1271 .withHttpRequest(testContext.httpRequestParams)1272 .resShouldBeCalledWith('send', testContext.expectedResponse)1273 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1274 .resDoesReturnSelf('status')1275 .test(done);1276 });1277 it('should handle first call to mock throwing an error.', function (done) {1278 testContext.setupGetFirstName = function () {1279 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;1280 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];1281 testContext.getFirstName1Result = new Error(testContext.expectedErrorMessage);1282 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1283 testContext.getFirstName2Result = random.firstName();1284 };1285 testContext.setupExpected = function () {1286 testContext.expectedResponse = [testContext.expectedErrorMessage];1287 testContext.expectedStatusCode = [404];1288 };1289 testContext.setupTest();1290 testContext.setupHttpRequest();1291 testContext.setupGetFirstName();1292 testContext.setupGetMiddleName();1293 testContext.setupGetLastName();1294 testContext.setupExpected();1295 new Scenario(this)1296 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1297 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1298 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1299 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1300 .withHttpRequest(testContext.httpRequestParams)1301 .resShouldBeCalledWith('send', testContext.expectedResponse)1302 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1303 .resDoesReturnSelf('status')1304 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1305 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1306 .test(done);1307 });1308 it('should handle second call to mock throwing an error.', function (done) {1309 testContext.setupGetFirstName = function () {1310 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;1311 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];1312 testContext.getFirstName1Result = random.firstName();1313 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1314 testContext.getFirstName2Result = new Error(testContext.expectedErrorMessage);1315 };1316 testContext.setupExpected = function () {1317 testContext.expectedResponse = [testContext.expectedErrorMessage];1318 testContext.expectedStatusCode = [404];1319 };1320 testContext.setupTest();1321 testContext.setupHttpRequest();1322 testContext.setupGetFirstName();1323 testContext.setupGetMiddleName();1324 testContext.setupGetLastName();1325 testContext.setupExpected();1326 new Scenario(this)1327 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1328 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1329 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1330 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1331 .withHttpRequest(testContext.httpRequestParams)1332 .resShouldBeCalledWith('send', testContext.expectedResponse)1333 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1334 .resDoesReturnSelf('status')1335 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1336 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1337 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)1338 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)1339 .test(done);1340 });1341 it('should handle mock throwing an error with a promise.', function (done) {1342 testContext.setupGetFirstName = function () {1343 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;1344 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];1345 testContext.getFirstName1Result = new Error(testContext.expectedErrorMessage);1346 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1347 testContext.getFirstName2Result = random.firstName();1348 };1349 testContext.setupExpected = function () {1350 testContext.expectedResponse = [testContext.expectedErrorMessage];1351 testContext.expectedStatusCode = [404];1352 };1353 testContext.setupTest();1354 testContext.setupHttpRequest();1355 testContext.setupGetFirstName();1356 testContext.setupGetMiddleName();1357 testContext.setupGetLastName();1358 testContext.setupExpected();1359 new Scenario(this)1360 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1361 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1362 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1363 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1364 .withHttpRequest(testContext.httpRequestParams)1365 .resShouldBeCalledWith('send', testContext.expectedResponse)1366 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1367 .resDoesReturnSelf('status')1368 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1369 .doesErrorWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1370 .test(done);1371 });1372 it('should handle mock throwing an error with a callback.', function (done) {1373 testContext.setupGetLastName = function () {1374 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;1375 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];1376 testContext.getLastNameResult = [new Error(testContext.expectedErrorMessage)];1377 };1378 testContext.setupExpected = function () {1379 testContext.expectedResponse = [testContext.expectedErrorMessage];1380 testContext.expectedStatusCode = [404];1381 };1382 testContext.setupTest();1383 testContext.setupHttpRequest();1384 testContext.setupGetFirstName();1385 testContext.setupGetMiddleName();1386 testContext.setupGetLastName();1387 testContext.setupExpected();1388 new Scenario(this)1389 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1390 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1391 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1392 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1393 .withHttpRequest(testContext.httpRequestParams)1394 .resShouldBeCalledWith('send', testContext.expectedResponse)1395 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1396 .resDoesReturnSelf('status')1397 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1398 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1399 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)1400 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)1401 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)1402 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)1403 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)1404 .doesErrorWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)1405 .test(done);1406 });1407 it('should handle mock throwing an error synchronously.', function (done) {1408 testContext.setupGetMiddleName = function () {1409 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;1410 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];1411 testContext.getMiddleNameResult = new Error(testContext.expectedErrorMessage);1412 };1413 testContext.setupExpected = function () {1414 testContext.expectedResponse = [testContext.expectedErrorMessage];1415 testContext.expectedStatusCode = [404];1416 };1417 testContext.setupTest();1418 testContext.setupHttpRequest();1419 testContext.setupGetFirstName();1420 testContext.setupGetMiddleName();1421 testContext.setupGetLastName();1422 testContext.setupExpected();1423 new Scenario(this)1424 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1425 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1426 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1427 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1428 .withHttpRequest(testContext.httpRequestParams)1429 .resShouldBeCalledWith('send', testContext.expectedResponse)1430 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1431 .resDoesReturnSelf('status')1432 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1433 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1434 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)1435 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)1436 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)1437 .doesError('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)1438 .test(done);1439 });1440 });1441 describe('when using the noDebug flag, it', function () {1442 beforeEach(function () {1443 testContext = {};1444 testContext.setupTest = function () {1445 testContext.entryPointObject = Controller;1446 testContext.entryPointFunction = 'statelessEs6Proxy';1447 testContext.proxyInstance = StatelessEs6Proxy;1448 };1449 testContext.setupHttpRequest = function () {1450 testContext.httpRequest = {1451 params: {1452 personId: '123456789'1453 },1454 query: {1455 homeState: 'IL'1456 }1457 };1458 testContext.httpRequestParams = [testContext.httpRequest];1459 };1460 testContext.setupGetFirstName = function () {1461 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];1462 testContext.getFirstName1Result = random.firstName();1463 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1464 testContext.getFirstName2Result = random.firstName();1465 };1466 testContext.setupGetMiddleName = function () {1467 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];1468 testContext.getMiddleNameResult = random.firstName();1469 };1470 testContext.setupGetLastName = function () {1471 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];1472 testContext.getLastNameResult = [undefined, random.lastName()];1473 };1474 testContext.setupExpected = function () {1475 testContext.intentionalWrongResponse = ['SOME WRONG RESPONSE'];1476 testContext.expectedStatusCode = [404];1477 testContext.expectedResponse = `Debug Params: {\n "actual": "${testContext.expectedErrorMessage}",\n "expected": "${testContext.intentionalWrongResponse[0]}"`;1478 };1479 });1480 it('should add the full object print out of actual and expected when the noDebug flag is NOT set.', function (done) {1481 testContext.setupGetMiddleName = function () {1482 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;1483 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];1484 testContext.getMiddleNameResult = new Error(testContext.expectedErrorMessage);1485 };1486 testContext.setupTest();1487 testContext.setupHttpRequest();1488 testContext.setupGetFirstName();1489 testContext.setupGetMiddleName();1490 testContext.setupGetLastName();1491 testContext.setupExpected();1492 new Scenario(this)1493 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1494 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1495 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1496 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1497 .withHttpRequest(testContext.httpRequestParams)1498 .resShouldBeCalledWith('send', testContext.intentionalWrongResponse)1499 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1500 .resDoesReturnSelf('status')1501 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1502 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1503 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)1504 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)1505 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)1506 .doesError('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)1507 .test(function () {1508 done(new Error('Should not reach here.'));1509 }).catch((err) => {1510 try {1511 Maddox.compare.shouldEqual({ actual: err.stack.split(testContext.expectedResponse).length, expected: 2 });1512 done();1513 } catch (testErr) {1514 done(err);1515 }1516 });1517 });1518 it('should NOT add the full object print out of actual and expected when the noDebug flag IS set.', function (done) {1519 testContext.setupGetMiddleName = function () {1520 testContext.expectedErrorMessage = `Proxy Error (${random.uniqueId()}): Some Proxy Error.`;1521 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];1522 testContext.getMiddleNameResult = new Error(testContext.expectedErrorMessage);1523 };1524 testContext.setupTest();1525 testContext.setupHttpRequest();1526 testContext.setupGetFirstName();1527 testContext.setupGetMiddleName();1528 testContext.setupGetLastName();1529 testContext.setupExpected();1530 new Scenario(this)1531 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1532 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1533 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1534 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1535 .withHttpRequest(testContext.httpRequestParams)1536 .resShouldBeCalledWith('send', testContext.intentionalWrongResponse)1537 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1538 .resDoesReturnSelf('status')1539 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)1540 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1541 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)1542 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)1543 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)1544 .doesError('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)1545 .noDebug()1546 .test(function () {1547 done(new Error('Should not reach here.'));1548 }).catch((err) => {1549 try {1550 Maddox.compare.shouldEqual({ actual: err.stack.split(testContext.expectedResponse).length, expected: 1 });1551 done();1552 } catch (testErr) {1553 done(testErr);1554 }1555 });1556 });1557 });1558 describe('when using shouldAlways / doesAlways, it', function () {1559 beforeEach(function () {1560 testContext = {};1561 testContext.setupTest = function () {1562 testContext.entryPointObject = SpecialScenariosController;1563 testContext.entryPointFunction = 'shouldAlwaysDoesAlways';1564 testContext.proxyInstance = StatelessEs6Proxy;1565 };1566 testContext.setupHttpRequest = function () {1567 testContext.httpRequest = {1568 params: {1569 personId: '123456789'1570 },1571 query: {1572 homeState: 'IL'1573 }1574 };1575 testContext.httpRequestParams = [testContext.httpRequest];1576 };1577 testContext.setupGetFirstName = function () {1578 testContext.getFirstNameParams = [testContext.httpRequest.params.personId, testContext.httpRequest.query.homeState];1579 testContext.getFirstName1Result = random.firstName();1580 testContext.getFirstName2Result = random.firstName();1581 testContext.getFirstName3Result = random.firstName();1582 };1583 testContext.setupGetMiddleName = function () {1584 testContext.getMiddleName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1585 testContext.getMiddleName1Result = random.firstName();1586 testContext.getMiddleName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];1587 testContext.getMiddleName2Result = random.firstName();1588 testContext.getMiddleName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName3Result];1589 testContext.getMiddleName3Result = random.firstName();1590 };1591 testContext.setupGetLastName = function () {1592 testContext.getLastName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];1593 testContext.getLastName1Result = [undefined, random.lastName()];1594 testContext.getLastName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleName2Result];1595 testContext.getLastName2Result = [undefined, random.lastName()];1596 testContext.getLastName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName3Result, testContext.getMiddleName3Result];1597 testContext.getLastName3Result = [undefined, random.lastName()];1598 };1599 testContext.setupExpected = function () {1600 testContext.expectedResponse = [{1601 personId: testContext.httpRequest.params.personId,1602 homeState: testContext.httpRequest.query.homeState,1603 lastName1: testContext.getLastName1Result[1],1604 lastName2: testContext.getLastName2Result[1],1605 lastName3: testContext.getLastName3Result[1]1606 }];1607 testContext.expectedStatusCode = [200];1608 };1609 });1610 it('should process when using shouldAlways for some proxy calls, but not using doesAlways for any proxy calls.', function (done) {1611 testContext.setupTest();1612 testContext.setupHttpRequest();1613 testContext.setupGetFirstName();1614 testContext.setupGetMiddleName();1615 testContext.setupGetLastName();1616 testContext.setupExpected();1617 new Scenario(this)1618 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1619 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1620 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1621 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1622 .withHttpRequest(testContext.httpRequestParams)1623 .resShouldBeCalledWith('send', testContext.expectedResponse)1624 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1625 .resDoesReturnSelf('status')1626 .shouldAlwaysBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstNameParams)1627 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1628 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)1629 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName3Result)1630 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName1Params)1631 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName1Result)1632 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName2Params)1633 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName2Result)1634 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName3Params)1635 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName3Result)1636 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName1Params)1637 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName1Result)1638 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName2Params)1639 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName2Result)1640 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName3Params)1641 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName3Result)1642 .test(done);1643 });1644 it('should process when using shouldAlways for some proxy calls, when using doesAlways for some proxy calls.', function (done) {1645 testContext.setupGetMiddleName = function () {1646 testContext.getMiddleName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1647 testContext.getMiddleName1Result = random.firstName();1648 testContext.getMiddleName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1649 testContext.getMiddleName2Result = random.firstName();1650 testContext.getMiddleName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1651 testContext.getMiddleName3Result = random.firstName();1652 };1653 testContext.setupGetLastName = function () {1654 testContext.getLastName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];1655 testContext.getLastName1Result = [undefined, random.lastName()];1656 testContext.getLastName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName2Result];1657 testContext.getLastName2Result = [undefined, random.lastName()];1658 testContext.getLastName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName3Result];1659 testContext.getLastName3Result = [undefined, random.lastName()];1660 };1661 testContext.setupTest();1662 testContext.setupHttpRequest();1663 testContext.setupGetFirstName();1664 testContext.setupGetMiddleName();1665 testContext.setupGetLastName();1666 testContext.setupExpected();1667 new Scenario(this)1668 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1669 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1670 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1671 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1672 .withHttpRequest(testContext.httpRequestParams)1673 .resShouldBeCalledWith('send', testContext.expectedResponse)1674 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1675 .resDoesReturnSelf('status')1676 .shouldAlwaysBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstNameParams)1677 .doesAlwaysReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1678 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName1Params)1679 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName1Result)1680 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName2Params)1681 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName2Result)1682 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName3Params)1683 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName3Result)1684 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName1Params)1685 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName1Result)1686 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName2Params)1687 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName2Result)1688 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName3Params)1689 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName3Result)1690 .test(done);1691 });1692 it('should process when using shouldAlways for some proxy calls, when using doesAlways for all proxy calls.', function (done) {1693 testContext.setupGetMiddleName = function () {1694 testContext.getMiddleName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1695 testContext.getMiddleName1Result = random.firstName();1696 testContext.getMiddleName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1697 testContext.getMiddleName2Result = random.firstName();1698 testContext.getMiddleName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1699 testContext.getMiddleName3Result = random.firstName();1700 };1701 testContext.setupGetLastName = function () {1702 testContext.getLastName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];1703 testContext.getLastName1Result = [undefined, random.lastName()];1704 testContext.getLastName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];1705 testContext.getLastName2Result = [undefined, random.lastName()];1706 testContext.getLastName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];1707 testContext.getLastName3Result = [undefined, random.lastName()];1708 };1709 testContext.setupExpected = function () {1710 testContext.expectedResponse = [{1711 personId: testContext.httpRequest.params.personId,1712 homeState: testContext.httpRequest.query.homeState,1713 lastName1: testContext.getLastName1Result[1],1714 lastName2: testContext.getLastName1Result[1],1715 lastName3: testContext.getLastName1Result[1]1716 }];1717 testContext.expectedStatusCode = [200];1718 };1719 testContext.setupTest();1720 testContext.setupHttpRequest();1721 testContext.setupGetFirstName();1722 testContext.setupGetMiddleName();1723 testContext.setupGetLastName();1724 testContext.setupExpected();1725 new Scenario(this)1726 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1727 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1728 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1729 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1730 .withHttpRequest(testContext.httpRequestParams)1731 .resShouldBeCalledWith('send', testContext.expectedResponse)1732 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1733 .resDoesReturnSelf('status')1734 .shouldAlwaysBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstNameParams)1735 .doesAlwaysReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1736 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName1Params)1737 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName2Params)1738 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName3Params)1739 .doesAlwaysReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName1Result)1740 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName1Params)1741 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName2Params)1742 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName3Params)1743 .doesAlwaysReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName1Result)1744 .test(done);1745 });1746 it('should process when using shouldAlways for all proxy calls, when using doesAlways for all proxy calls.', function (done) {1747 testContext.setupGetMiddleName = function () {1748 testContext.getMiddleName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1749 testContext.getMiddleName1Result = random.firstName();1750 };1751 testContext.setupGetLastName = function () {1752 testContext.getLastName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];1753 testContext.getLastName1Result = [undefined, random.lastName()];1754 };1755 testContext.setupExpected = function () {1756 testContext.expectedResponse = [{1757 personId: testContext.httpRequest.params.personId,1758 homeState: testContext.httpRequest.query.homeState,1759 lastName1: testContext.getLastName1Result[1],1760 lastName2: testContext.getLastName1Result[1],1761 lastName3: testContext.getLastName1Result[1]1762 }];1763 testContext.expectedStatusCode = [200];1764 };1765 testContext.setupTest();1766 testContext.setupHttpRequest();1767 testContext.setupGetFirstName();1768 testContext.setupGetMiddleName();1769 testContext.setupGetLastName();1770 testContext.setupExpected();1771 new Scenario(this)1772 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1773 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1774 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1775 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1776 .withHttpRequest(testContext.httpRequestParams)1777 .resShouldBeCalledWith('send', testContext.expectedResponse)1778 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1779 .resDoesReturnSelf('status')1780 .shouldAlwaysBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstNameParams)1781 .doesAlwaysReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1782 .shouldAlwaysBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName1Params)1783 .doesAlwaysReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName1Result)1784 .shouldAlwaysBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName1Params)1785 .doesAlwaysReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName1Result)1786 .test(done);1787 });1788 });1789 describe('when using shouldAlwaysWithSubset, it', function () {1790 beforeEach(function () {1791 testContext = {};1792 testContext.setupTest = function () {1793 testContext.entryPointObject = SpecialScenariosController;1794 testContext.entryPointFunction = 'shouldAlwaysDoesAlways';1795 testContext.proxyInstance = StatelessEs6Proxy;1796 };1797 testContext.setupHttpRequest = function () {1798 testContext.httpRequest = {1799 params: {1800 personId: '123456789'1801 },1802 query: {1803 homeState: 'ILLINOIS'1804 }1805 };1806 testContext.httpRequestParams = [testContext.httpRequest];1807 };1808 testContext.setupGetFirstName = function () {1809 const firstNameSubString = testContext.httpRequest.params.personId.substring(1, 5);1810 const homeStateSubString = testContext.httpRequest.query.homeState.substring(2, 7);1811 testContext.getFirstNameParams = [firstNameSubString, homeStateSubString];1812 testContext.getFirstName1Result = random.firstName();1813 testContext.getFirstName2Result = random.firstName();1814 testContext.getFirstName3Result = random.firstName();1815 };1816 testContext.setupGetMiddleName = function () {1817 testContext.getMiddleName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1818 testContext.getMiddleName1Result = random.firstName();1819 testContext.getMiddleName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];1820 testContext.getMiddleName2Result = random.firstName();1821 testContext.getMiddleName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName3Result];1822 testContext.getMiddleName3Result = random.firstName();1823 };1824 testContext.setupGetLastName = function () {1825 testContext.getLastName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];1826 testContext.getLastName1Result = [undefined, random.lastName()];1827 testContext.getLastName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleName2Result];1828 testContext.getLastName2Result = [undefined, random.lastName()];1829 testContext.getLastName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName3Result, testContext.getMiddleName3Result];1830 testContext.getLastName3Result = [undefined, random.lastName()];1831 };1832 testContext.setupExpected = function () {1833 testContext.expectedResponse = [{1834 personId: testContext.httpRequest.params.personId,1835 homeState: testContext.httpRequest.query.homeState,1836 lastName1: testContext.getLastName1Result[1],1837 lastName2: testContext.getLastName2Result[1],1838 lastName3: testContext.getLastName3Result[1]1839 }];1840 testContext.expectedStatusCode = [200];1841 };1842 });1843 it('should process when using shouldAlwaysWithSubset for some proxy calls, but not using doesAlways for any proxy calls.', function (done) {1844 testContext.setupTest();1845 testContext.setupHttpRequest();1846 testContext.setupGetFirstName();1847 testContext.setupGetMiddleName();1848 testContext.setupGetLastName();1849 testContext.setupExpected();1850 new Scenario(this)1851 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1852 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1853 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1854 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1855 .withHttpRequest(testContext.httpRequestParams)1856 .resShouldBeCalledWith('send', testContext.expectedResponse)1857 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1858 .resDoesReturnSelf('status')1859 .shouldAlwaysBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstNameParams)1860 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1861 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)1862 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName3Result)1863 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName1Params)1864 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName1Result)1865 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName2Params)1866 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName2Result)1867 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName3Params)1868 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName3Result)1869 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName1Params)1870 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName1Result)1871 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName2Params)1872 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName2Result)1873 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName3Params)1874 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName3Result)1875 .test(done);1876 });1877 it('should process when using shouldAlwaysWithSubset for some proxy calls, when using doesAlways for some proxy calls.', function (done) {1878 testContext.setupGetMiddleName = function () {1879 testContext.getMiddleName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1880 testContext.getMiddleName1Result = random.firstName();1881 testContext.getMiddleName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1882 testContext.getMiddleName2Result = random.firstName();1883 testContext.getMiddleName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1884 testContext.getMiddleName3Result = random.firstName();1885 };1886 testContext.setupGetLastName = function () {1887 testContext.getLastName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];1888 testContext.getLastName1Result = [undefined, random.lastName()];1889 testContext.getLastName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName2Result];1890 testContext.getLastName2Result = [undefined, random.lastName()];1891 testContext.getLastName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName3Result];1892 testContext.getLastName3Result = [undefined, random.lastName()];1893 };1894 testContext.setupTest();1895 testContext.setupHttpRequest();1896 testContext.setupGetFirstName();1897 testContext.setupGetMiddleName();1898 testContext.setupGetLastName();1899 testContext.setupExpected();1900 new Scenario(this)1901 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1902 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1903 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1904 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1905 .withHttpRequest(testContext.httpRequestParams)1906 .resShouldBeCalledWith('send', testContext.expectedResponse)1907 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1908 .resDoesReturnSelf('status')1909 .shouldAlwaysBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstNameParams)1910 .doesAlwaysReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1911 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName1Params)1912 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName1Result)1913 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName2Params)1914 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName2Result)1915 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName3Params)1916 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName3Result)1917 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName1Params)1918 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName1Result)1919 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName2Params)1920 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName2Result)1921 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName3Params)1922 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName3Result)1923 .test(done);1924 });1925 it('should process when using shouldAlwaysWithSubset for some proxy calls, when using doesAlways for all proxy calls.', function (done) {1926 testContext.setupGetMiddleName = function () {1927 testContext.getMiddleName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1928 testContext.getMiddleName1Result = random.firstName();1929 testContext.getMiddleName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1930 testContext.getMiddleName2Result = random.firstName();1931 testContext.getMiddleName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];1932 testContext.getMiddleName3Result = random.firstName();1933 };1934 testContext.setupGetLastName = function () {1935 testContext.getLastName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];1936 testContext.getLastName1Result = [undefined, random.lastName()];1937 testContext.getLastName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];1938 testContext.getLastName2Result = [undefined, random.lastName()];1939 testContext.getLastName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];1940 testContext.getLastName3Result = [undefined, random.lastName()];1941 };1942 testContext.setupExpected = function () {1943 testContext.expectedResponse = [{1944 personId: testContext.httpRequest.params.personId,1945 homeState: testContext.httpRequest.query.homeState,1946 lastName1: testContext.getLastName1Result[1],1947 lastName2: testContext.getLastName1Result[1],1948 lastName3: testContext.getLastName1Result[1]1949 }];1950 testContext.expectedStatusCode = [200];1951 };1952 testContext.setupTest();1953 testContext.setupHttpRequest();1954 testContext.setupGetFirstName();1955 testContext.setupGetMiddleName();1956 testContext.setupGetLastName();1957 testContext.setupExpected();1958 new Scenario(this)1959 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)1960 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)1961 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)1962 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)1963 .withHttpRequest(testContext.httpRequestParams)1964 .resShouldBeCalledWith('send', testContext.expectedResponse)1965 .resShouldBeCalledWith('status', testContext.expectedStatusCode)1966 .resDoesReturnSelf('status')1967 .shouldAlwaysBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstNameParams)1968 .doesAlwaysReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)1969 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName1Params)1970 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName2Params)1971 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName3Params)1972 .doesAlwaysReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName1Result)1973 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName1Params)1974 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName2Params)1975 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName3Params)1976 .doesAlwaysReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName1Result)1977 .test(done);1978 });1979 it('should process when using shouldAlwaysWithSubset for all proxy calls, when using doesAlways for all proxy calls.', function (done) {1980 testContext.setupGetMiddleName = function () {1981 const firstNameSubString = testContext.getFirstName1Result.substring(1, 2);1982 testContext.getMiddleName1Params = [testContext.httpRequest.params.personId, firstNameSubString];1983 testContext.getMiddleName1Result = random.firstName();1984 };1985 testContext.setupGetLastName = function () {1986 testContext.getLastName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];1987 testContext.getLastName1Result = [undefined, random.lastName()];1988 };1989 testContext.setupExpected = function () {1990 testContext.expectedResponse = [{1991 personId: testContext.httpRequest.params.personId,1992 homeState: testContext.httpRequest.query.homeState,1993 lastName1: testContext.getLastName1Result[1],1994 lastName2: testContext.getLastName1Result[1],1995 lastName3: testContext.getLastName1Result[1]1996 }];1997 testContext.expectedStatusCode = [200];1998 };1999 testContext.setupTest();2000 testContext.setupHttpRequest();2001 testContext.setupGetFirstName();2002 testContext.setupGetMiddleName();2003 testContext.setupGetLastName();2004 testContext.setupExpected();2005 new Scenario(this)2006 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2007 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2008 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2009 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2010 .withHttpRequest(testContext.httpRequestParams)2011 .resShouldBeCalledWith('send', testContext.expectedResponse)2012 .resShouldBeCalledWith('status', testContext.expectedStatusCode)2013 .resDoesReturnSelf('status')2014 .shouldAlwaysBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstNameParams)2015 .doesAlwaysReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2016 .shouldAlwaysBeCalledWithSubset('proxyInstance', 'getMiddleName', testContext.getMiddleName1Params)2017 .doesAlwaysReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName1Result)2018 .shouldAlwaysBeCalledWithSubset('proxyInstance', 'getLastName', testContext.getLastName1Params)2019 .doesAlwaysReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName1Result)2020 .test(done);2021 });2022 it('should process when using shouldAlwaysWithSubset some proxy calls, and shouldAlways for other proxy calls.', function (done) {2023 testContext.setupGetMiddleName = function () {2024 testContext.getMiddleName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];2025 testContext.getMiddleName1Result = random.firstName();2026 };2027 testContext.setupGetLastName = function () {2028 testContext.getLastName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result, testContext.getMiddleName1Result];2029 testContext.getLastName1Result = [undefined, random.lastName()];2030 };2031 testContext.setupExpected = function () {2032 testContext.expectedResponse = [{2033 personId: testContext.httpRequest.params.personId,2034 homeState: testContext.httpRequest.query.homeState,2035 lastName1: testContext.getLastName1Result[1],2036 lastName2: testContext.getLastName1Result[1],2037 lastName3: testContext.getLastName1Result[1]2038 }];2039 testContext.expectedStatusCode = [200];2040 };2041 testContext.setupTest();2042 testContext.setupHttpRequest();2043 testContext.setupGetFirstName();2044 testContext.setupGetMiddleName();2045 testContext.setupGetLastName();2046 testContext.setupExpected();2047 new Scenario(this)2048 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2049 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2050 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2051 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2052 .withHttpRequest(testContext.httpRequestParams)2053 .resShouldBeCalledWith('send', testContext.expectedResponse)2054 .resShouldBeCalledWith('status', testContext.expectedStatusCode)2055 .resDoesReturnSelf('status')2056 .shouldAlwaysBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstNameParams)2057 .doesAlwaysReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2058 .shouldAlwaysBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleName1Params)2059 .doesAlwaysReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName1Result)2060 .shouldAlwaysBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName1Params)2061 .doesAlwaysReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName1Result)2062 .test(done);2063 });2064 });2065 describe('when setting a test finisher function, it', function () {2066 beforeEach(function () {2067 testContext = {};2068 testContext.setupTest = function () {2069 testContext.entryPointObject = Controller;2070 testContext.entryPointFunction = 'statelessEs6Proxy';2071 testContext.proxyInstance = StatelessEs6Proxy;2072 };2073 testContext.setupHttpRequest = function () {2074 testContext.httpRequest = {2075 params: {2076 personId: '123456789'2077 },2078 query: {2079 homeState: 'IL'2080 }2081 };2082 testContext.httpRequestParams = [testContext.httpRequest];2083 };2084 testContext.setupGetFirstName = function () {2085 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];2086 testContext.getFirstName1Result = random.firstName();2087 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];2088 testContext.getFirstName2Result = random.firstName();2089 };2090 testContext.setupGetMiddleName = function () {2091 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];2092 testContext.getMiddleNameResult = random.firstName();2093 };2094 testContext.setupGetLastName = function () {2095 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];2096 testContext.getLastNameResult = [undefined, random.lastName()];2097 };2098 testContext.setupExpected = function () {2099 testContext.expectedResponse = [{2100 personId: testContext.httpRequest.params.personId,2101 homeState: testContext.httpRequest.query.homeState,2102 lastName: testContext.getLastNameResult[1]2103 }];2104 testContext.expectedStatusCode = [200];2105 };2106 });2107 it('should handle a finisher function that is defined before to the response finisher function.', function (done) {2108 testContext.setupTest();2109 testContext.setupHttpRequest();2110 testContext.setupGetFirstName();2111 testContext.setupGetMiddleName();2112 testContext.setupGetLastName();2113 testContext.setupExpected();2114 new Scenario(this)2115 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2116 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2117 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2118 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2119 .withHttpRequest(testContext.httpRequestParams)2120 .withTestFinisherFunction('proxyInstance', 'getFirstName', 0)2121 .resShouldAlwaysBeIgnored('send')2122 .resShouldAlwaysBeIgnored('status')2123 .resDoesReturnSelf('status')2124 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)2125 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2126 // Don't need a shouldBeCalledWith because it never gets called2127 // .shouldAlwaysBeIgnored("proxyInstance", "getFirstName")2128 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2129 // Don't need a shouldBeCalledWith because it never gets called2130 // .shouldAlwaysBeIgnored("proxyInstance", "getMiddleName")2131 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2132 // Don't need a shouldBeCalledWith because it never gets called2133 // .shouldAlwaysBeIgnored("proxyInstance", "getLastName")2134 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2135 .test(done);2136 });2137 it('should handle a finisher function that is defined after to the response finisher function.', function (done) {2138 testContext.setupTest();2139 testContext.setupHttpRequest();2140 testContext.setupGetFirstName();2141 testContext.setupGetMiddleName();2142 testContext.setupGetLastName();2143 testContext.setupExpected();2144 new Scenario(this)2145 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2146 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2147 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2148 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2149 .withHttpRequest(testContext.httpRequestParams)2150 .resShouldAlwaysBeIgnored('send')2151 .resShouldAlwaysBeIgnored('status')2152 .resDoesReturnSelf('status')2153 .withTestFinisherFunction('proxyInstance', 'getFirstName', 0)2154 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)2155 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2156 // Don't need a shouldBeCalledWith because it never gets called2157 // .shouldAlwaysBeIgnored("proxyInstance", "getFirstName")2158 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2159 // Don't need a shouldBeCalledWith because it never gets called2160 // .shouldAlwaysBeIgnored("proxyInstance", "getMiddleName")2161 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2162 // Don't need a shouldBeCalledWith because it never gets called2163 // .shouldAlwaysBeIgnored("proxyInstance", "getLastName")2164 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2165 .test(done);2166 });2167 it('should handle a finisher function with an iteration greater than 0.', function (done) {2168 testContext.setupTest();2169 testContext.setupHttpRequest();2170 testContext.setupGetFirstName();2171 testContext.setupGetMiddleName();2172 testContext.setupGetLastName();2173 testContext.setupExpected();2174 new Scenario(this)2175 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2176 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2177 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2178 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2179 .withHttpRequest(testContext.httpRequestParams)2180 .resShouldAlwaysBeIgnored('send')2181 .resShouldAlwaysBeIgnored('status')2182 .resDoesReturnSelf('status')2183 .withTestFinisherFunction('proxyInstance', 'getFirstName', 1)2184 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)2185 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2186 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)2187 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2188 // Don't need a shouldBeCalledWith because it never gets called2189 // .shouldAlwaysBeIgnored("proxyInstance", "getMiddleName")2190 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2191 // Don't need a shouldBeCalledWith because it never gets called2192 // .shouldAlwaysBeIgnored("proxyInstance", "getLastName")2193 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2194 .test(done);2195 });2196 it('should default finisher function \'iteration\' property to 0.', function (done) {2197 testContext.setupTest();2198 testContext.setupHttpRequest();2199 testContext.setupGetFirstName();2200 testContext.setupGetMiddleName();2201 testContext.setupGetLastName();2202 testContext.setupExpected();2203 new Scenario(this)2204 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2205 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2206 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2207 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2208 .withHttpRequest(testContext.httpRequestParams)2209 .resShouldAlwaysBeIgnored('send')2210 .resShouldAlwaysBeIgnored('status')2211 .resDoesReturnSelf('status')2212 .withTestFinisherFunction('proxyInstance', 'getFirstName')2213 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)2214 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2215 // Don't need a shouldBeCalledWith because it never gets called2216 // .shouldAlwaysBeIgnored("proxyInstance", "getFirstName")2217 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2218 // Don't need a shouldBeCalledWith because it never gets called2219 // .shouldAlwaysBeIgnored("proxyInstance", "getMiddleName")2220 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2221 // Don't need a shouldBeCalledWith because it never gets called2222 // .shouldAlwaysBeIgnored("proxyInstance", "getLastName")2223 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2224 .test(done);2225 });2226 it('should handle a finisher function but still test all prior mocks.', function (done) {2227 testContext.setupTest();2228 testContext.setupHttpRequest();2229 testContext.setupGetFirstName();2230 testContext.setupGetMiddleName();2231 testContext.setupGetLastName();2232 testContext.setupExpected();2233 new Scenario(this)2234 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2235 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2236 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2237 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2238 .withHttpRequest(testContext.httpRequestParams)2239 .resShouldAlwaysBeIgnored('send')2240 .resShouldAlwaysBeIgnored('status')2241 .resDoesReturnSelf('status')2242 .withTestFinisherFunction('proxyInstance', 'getLastName', 0)2243 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)2244 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2245 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)2246 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2247 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)2248 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2249 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)2250 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2251 .test(done);2252 });2253 });2254 describe('when changing the state of a shouldBeCalledWith through out the code, it', function () {2255 beforeEach(function () {2256 testContext = {};2257 testContext.setupTest = function () {2258 testContext.entryPointObject = SpecialScenariosController;2259 testContext.entryPointFunction = 'modifyingContext';2260 testContext.proxyInstance = StatelessEs6Proxy;2261 };2262 testContext.setupHttpRequest = function () {2263 testContext.httpRequest = {};2264 testContext.httpRequestParams = [testContext.httpRequest];2265 };2266 testContext.setupGetFirstName = function () {2267 testContext.getFirstName1Params = [{2268 someValue1: 'first'2269 }];2270 testContext.getFirstName2Params = [{2271 someValue1: 'first',2272 someValue2: 'second'2273 }];2274 testContext.getFirstName3Params = [{2275 someValue1: 'first',2276 someValue2: 'second',2277 someValue3: 'third'2278 }];2279 testContext.getFirstNameResult = random.firstName();2280 };2281 testContext.setupExpected = function () {2282 testContext.expectedResponse = [{2283 someValue1: 'first',2284 someValue2: 'second',2285 someValue3: 'third'2286 }];2287 testContext.expectedStatusCode = [200];2288 };2289 });2290 it('should test the mock inputParams with the state that they were called with.', function (done) {2291 testContext.setupTest();2292 testContext.setupHttpRequest();2293 testContext.setupGetFirstName();2294 testContext.setupExpected();2295 new Scenario(this)2296 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2297 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2298 .withHttpRequest(testContext.httpRequestParams)2299 .resShouldBeCalledWith('send', testContext.expectedResponse)2300 .resShouldBeCalledWith('status', testContext.expectedStatusCode)2301 .resDoesReturnSelf('status')2302 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)2303 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)2304 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName3Params)2305 .doesAlwaysReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstNameResult)2306 .test(done);2307 });2308 });2309 describe('when using shouldAlwaysIgnore, it', function () {2310 beforeEach(function () {2311 testContext = {};2312 testContext.setupTest = function () {2313 testContext.entryPointObject = SpecialScenariosController;2314 testContext.entryPointFunction = 'shouldAlwaysDoesAlways';2315 testContext.proxyInstance = StatelessEs6Proxy;2316 };2317 testContext.setupHttpRequest = function () {2318 testContext.httpRequest = {2319 params: {2320 personId: '123456789'2321 },2322 query: {2323 homeState: 'IL'2324 }2325 };2326 testContext.httpRequestParams = [testContext.httpRequest];2327 };2328 testContext.setupGetFirstName = function () {2329 testContext.getFirstNameParams = ['WrongAnswer', testContext.httpRequest.query.homeState];2330 testContext.getFirstName1Result = random.firstName();2331 testContext.getFirstName2Result = random.firstName();2332 testContext.getFirstName3Result = random.firstName();2333 };2334 testContext.setupGetMiddleName = function () {2335 testContext.getMiddleName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];2336 testContext.getMiddleName1Result = random.firstName();2337 testContext.getMiddleName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];2338 testContext.getMiddleName2Result = random.firstName();2339 testContext.getMiddleName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName3Result];2340 testContext.getMiddleName3Result = random.firstName();2341 };2342 testContext.setupGetLastName = function () {2343 testContext.getLastName1Params = ['WrongAnswer', testContext.getFirstName1Result, testContext.getMiddleName1Result];2344 testContext.getLastName1Result = [undefined, random.lastName()];2345 testContext.getLastName2Params = ['WrongAnswer', testContext.getFirstName2Result, testContext.getMiddleName2Result];2346 testContext.getLastName2Result = [undefined, random.lastName()];2347 testContext.getLastName3Params = ['WrongAnswer', testContext.getFirstName3Result, testContext.getMiddleName3Result];2348 testContext.getLastName3Result = [undefined, random.lastName()];2349 };2350 testContext.setupExpected = function () {2351 testContext.expectedResponse = [{2352 personId: testContext.httpRequest.params.personId,2353 homeState: testContext.httpRequest.query.homeState,2354 lastName1: testContext.getLastName1Result[1],2355 lastName2: testContext.getLastName2Result[1],2356 lastName3: testContext.getLastName3Result[1]2357 }];2358 testContext.expectedStatusCode = [200];2359 };2360 });2361 it('should process when using shouldAlwaysIgnore', function (done) {2362 testContext.setupTest();2363 testContext.setupHttpRequest();2364 testContext.setupGetFirstName();2365 testContext.setupGetMiddleName();2366 testContext.setupGetLastName();2367 testContext.setupExpected();2368 new Scenario(this)2369 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2370 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2371 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2372 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2373 .withHttpRequest(testContext.httpRequestParams)2374 .resShouldBeCalledWith('send', testContext.expectedResponse)2375 .resShouldBeCalledWith('status', testContext.expectedStatusCode)2376 .resDoesReturnSelf('status')2377 .shouldAlwaysBeIgnored('proxyInstance', 'getFirstName', testContext.getFirstNameParams)2378 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2379 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2380 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName3Result)2381 .shouldAlwaysBeIgnored('proxyInstance', 'getMiddleName')2382 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName1Result)2383 .shouldAlwaysBeIgnored('proxyInstance', 'getMiddleName')2384 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName2Result)2385 .shouldAlwaysBeIgnored('proxyInstance', 'getMiddleName')2386 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName3Result)2387 .shouldAlwaysBeIgnored('proxyInstance', 'getLastName')2388 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName1Result)2389 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName2Params)2390 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName2Result)2391 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName3Params)2392 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName3Result)2393 .test(done);2394 });2395 });2396 describe('when using shouldBeCalled, it', function () {2397 beforeEach(function () {2398 testContext = {};2399 testContext.setupTest = function () {2400 testContext.entryPointObject = Controller;2401 testContext.entryPointFunction = 'statelessEs6Proxy';2402 testContext.proxyInstance = StatelessEs6Proxy;2403 };2404 testContext.setupHttpRequest = function () {2405 testContext.httpRequest = {2406 params: {2407 personId: '123456789'2408 },2409 query: {2410 homeState: 'IL'2411 }2412 };2413 testContext.httpRequestParams = [testContext.httpRequest];2414 };2415 testContext.setupGetFirstName = function () {2416 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];2417 testContext.getFirstName1Result = random.firstName();2418 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];2419 testContext.getFirstName2Result = random.firstName();2420 };2421 testContext.setupGetMiddleName = function () {2422 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];2423 testContext.getMiddleNameResult = random.firstName();2424 };2425 testContext.setupGetLastName = function () {2426 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];2427 testContext.getLastNameResult = [undefined, random.lastName()];2428 };2429 testContext.setupExpected = function () {2430 testContext.expectedResponse = [{2431 personId: testContext.httpRequest.params.personId,2432 homeState: testContext.httpRequest.query.homeState,2433 lastName: testContext.getLastNameResult[1]2434 }];2435 testContext.expectedStatusCode = [200];2436 };2437 });2438 it('should allow all mocked functions to use \'shouldBeCalled\'.', function (done) {2439 testContext.setupTest();2440 testContext.setupHttpRequest();2441 testContext.setupGetFirstName();2442 testContext.setupGetMiddleName();2443 testContext.setupGetLastName();2444 testContext.setupExpected();2445 new Scenario(this)2446 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2447 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2448 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2449 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2450 .withHttpRequest(testContext.httpRequestParams)2451 .resShouldBeCalled('send')2452 .resShouldBeCalled('status')2453 .resDoesReturnSelf('status')2454 .shouldBeCalled('proxyInstance', 'getFirstName')2455 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2456 .shouldBeCalled('proxyInstance', 'getFirstName')2457 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2458 .shouldBeCalled('proxyInstance', 'getMiddleName')2459 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2460 .shouldBeCalled('proxyInstance', 'getLastName')2461 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2462 .perf()2463 .test(done);2464 });2465 it('should allow \'shouldBeCalled\' to be executed prior to a \'shouldBeCalledWith\'.', function (done) {2466 testContext.setupTest();2467 testContext.setupHttpRequest();2468 testContext.setupGetFirstName();2469 testContext.setupGetMiddleName();2470 testContext.setupGetLastName();2471 testContext.setupExpected();2472 new Scenario(this)2473 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2474 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2475 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2476 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2477 .withHttpRequest(testContext.httpRequestParams)2478 .resShouldBeCalled('send')2479 .resShouldBeCalled('status')2480 .resDoesReturnSelf('status')2481 .shouldBeCalled('proxyInstance', 'getFirstName')2482 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2483 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)2484 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2485 .shouldBeCalled('proxyInstance', 'getMiddleName')2486 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2487 .shouldBeCalled('proxyInstance', 'getLastName')2488 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2489 .perf()2490 .test(done);2491 });2492 it('should allow \'shouldBeCalledWith\' to be executed prior to a \'shouldBeCalled\'.', function (done) {2493 testContext.setupTest();2494 testContext.setupHttpRequest();2495 testContext.setupGetFirstName();2496 testContext.setupGetMiddleName();2497 testContext.setupGetLastName();2498 testContext.setupExpected();2499 new Scenario(this)2500 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2501 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2502 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2503 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2504 .withHttpRequest(testContext.httpRequestParams)2505 .resShouldBeCalled('send')2506 .resShouldBeCalled('status')2507 .resDoesReturnSelf('status')2508 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)2509 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2510 .shouldBeCalled('proxyInstance', 'getFirstName')2511 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2512 .shouldBeCalled('proxyInstance', 'getMiddleName')2513 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2514 .shouldBeCalled('proxyInstance', 'getLastName')2515 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2516 .perf()2517 .test(done);2518 });2519 it('should fail when a mock was expected to be called more than the actual.', function (done) {2520 testContext.setupExpected = function () {2521 testContext.expectedResponse = [{2522 personId: testContext.httpRequest.params.personId,2523 homeState: testContext.httpRequest.query.homeState,2524 lastName: testContext.getLastNameResult[1]2525 }];2526 testContext.expectedStatusCode = [200];2527 testContext.expectedErrorMessage = 'Maddox Runtime Error (3002): Expected the mock proxyInstance.getFirstName to be called 3 time(s), but it was actually called 2 time(s).';2528 };2529 testContext.setupTest();2530 testContext.setupHttpRequest();2531 testContext.setupGetFirstName();2532 testContext.setupGetMiddleName();2533 testContext.setupGetLastName();2534 testContext.setupExpected();2535 new Scenario(this)2536 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2537 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2538 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2539 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2540 .withHttpRequest(testContext.httpRequestParams)2541 .resShouldBeCalled('send')2542 .resShouldBeCalled('status')2543 .resDoesReturnSelf('status')2544 .shouldBeCalled('proxyInstance', 'getFirstName')2545 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2546 .shouldBeCalled('proxyInstance', 'getFirstName')2547 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2548 .shouldBeCalled('proxyInstance', 'getFirstName')2549 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2550 .shouldBeCalled('proxyInstance', 'getMiddleName')2551 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2552 .shouldBeCalled('proxyInstance', 'getLastName')2553 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2554 .perf()2555 .test(() => {2556 Maddox.compare.shouldBeUnreachable();2557 }).catch((err) => {2558 try {2559 Maddox.compare.equal(err.message, testContext.expectedErrorMessage);2560 done();2561 } catch (testError) {2562 done(testError);2563 }2564 });2565 });2566 it('should fail when a mock function was not called.', function (done) {2567 testContext.setupExpected = function () {2568 testContext.expectedResponse = [{2569 personId: testContext.httpRequest.params.personId,2570 homeState: testContext.httpRequest.query.homeState,2571 lastName: testContext.getLastNameResult[1]2572 }];2573 testContext.expectedStatusCode = [200];2574 testContext.expectedErrorMessage = 'Maddox Runtime Error (3002): Expected the mock proxyInstance.dummyFunction to be called 1 time(s), but it was actually called 0 time(s).';2575 };2576 testContext.setupTest();2577 testContext.setupHttpRequest();2578 testContext.setupGetFirstName();2579 testContext.setupGetMiddleName();2580 testContext.setupGetLastName();2581 testContext.setupExpected();2582 new Scenario(this)2583 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2584 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2585 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2586 .mockThisFunction('proxyInstance', 'dummyFunction', testContext.proxyInstance)2587 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2588 .withHttpRequest(testContext.httpRequestParams)2589 .resShouldBeCalled('send')2590 .resShouldBeCalled('status')2591 .resDoesReturnSelf('status')2592 .shouldBeCalled('proxyInstance', 'getFirstName')2593 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2594 .shouldBeCalled('proxyInstance', 'getFirstName')2595 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2596 .shouldBeCalled('proxyInstance', 'getMiddleName')2597 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2598 .shouldBeCalled('proxyInstance', 'getLastName')2599 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2600 .shouldBeCalled('proxyInstance', 'dummyFunction')2601 .doesReturnWithCallback('proxyInstance', 'dummyFunction', testContext.getLastNameResult)2602 .test(() => {2603 Maddox.compare.shouldBeUnreachable();2604 }).catch((err) => {2605 try {2606 Maddox.compare.equal(err.message, testContext.expectedErrorMessage);2607 done();2608 } catch (testError) {2609 done(testError);2610 }2611 });2612 });2613 it('should fail when a http response mock function was not called.', function (done) {2614 testContext.setupExpected = function () {2615 testContext.expectedResponse = [{2616 personId: testContext.httpRequest.params.personId,2617 homeState: testContext.httpRequest.query.homeState,2618 lastName: testContext.getLastNameResult[1]2619 }];2620 testContext.expectedStatusCode = [200];2621 testContext.expectedErrorMessage = 'Maddox Runtime Error (3002): Expected the mock HttpResponseMock.SomeUnknownFunction to be called 1 time(s), but it was actually called 0 time(s).';2622 };2623 testContext.setupTest();2624 testContext.setupHttpRequest();2625 testContext.setupGetFirstName();2626 testContext.setupGetMiddleName();2627 testContext.setupGetLastName();2628 testContext.setupExpected();2629 new Scenario(this)2630 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2631 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2632 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2633 .mockThisFunction('proxyInstance', 'dummyFunction', testContext.proxyInstance)2634 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2635 .withHttpRequest(testContext.httpRequestParams)2636 .resShouldBeCalled('send')2637 .resShouldBeCalled('SomeUnknownFunction')2638 .resShouldBeCalled('status')2639 .resDoesReturnSelf('status')2640 .shouldBeCalled('proxyInstance', 'getFirstName')2641 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2642 .shouldBeCalled('proxyInstance', 'getFirstName')2643 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2644 .shouldBeCalled('proxyInstance', 'getMiddleName')2645 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2646 .shouldBeCalled('proxyInstance', 'getLastName')2647 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2648 .test(() => {2649 Maddox.compare.shouldBeUnreachable();2650 }).catch((err) => {2651 try {2652 Maddox.compare.equal(err.message, testContext.expectedErrorMessage);2653 done();2654 } catch (testError) {2655 done(testError);2656 }2657 });2658 });2659 });2660 describe('when not passing in the test context, it', function () {2661 beforeEach(function () {2662 testContext = {};2663 testContext.setupTest = function () {2664 testContext.entryPointObject = SpecialScenariosController;2665 testContext.entryPointFunction = 'shouldAlwaysDoesAlways';2666 testContext.proxyInstance = StatelessEs6Proxy;2667 };2668 testContext.setupHttpRequest = function () {2669 testContext.httpRequest = {2670 params: {2671 personId: '123456789'2672 },2673 query: {2674 homeState: 'IL'2675 }2676 };2677 testContext.httpRequestParams = [testContext.httpRequest];2678 };2679 testContext.setupGetFirstName = function () {2680 testContext.getFirstNameParams = ['WrongAnswer', testContext.httpRequest.query.homeState];2681 testContext.getFirstName1Result = random.firstName();2682 testContext.getFirstName2Result = random.firstName();2683 testContext.getFirstName3Result = random.firstName();2684 };2685 testContext.setupGetMiddleName = function () {2686 testContext.getMiddleName1Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];2687 testContext.getMiddleName1Result = random.firstName();2688 testContext.getMiddleName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];2689 testContext.getMiddleName2Result = random.firstName();2690 testContext.getMiddleName3Params = [testContext.httpRequest.params.personId, testContext.getFirstName3Result];2691 testContext.getMiddleName3Result = random.firstName();2692 };2693 testContext.setupGetLastName = function () {2694 testContext.getLastName1Params = ['WrongAnswer', testContext.getFirstName1Result, testContext.getMiddleName1Result];2695 testContext.getLastName1Result = [undefined, random.lastName()];2696 testContext.getLastName2Params = ['WrongAnswer', testContext.getFirstName2Result, testContext.getMiddleName2Result];2697 testContext.getLastName2Result = [undefined, random.lastName()];2698 testContext.getLastName3Params = ['WrongAnswer', testContext.getFirstName3Result, testContext.getMiddleName3Result];2699 testContext.getLastName3Result = [undefined, random.lastName()];2700 };2701 testContext.setupExpected = function () {2702 testContext.expectedResponse = [{2703 personId: testContext.httpRequest.params.personId,2704 homeState: testContext.httpRequest.query.homeState,2705 lastName1: testContext.getLastName1Result[1],2706 lastName2: testContext.getLastName2Result[1],2707 lastName3: testContext.getLastName3Result[1]2708 }];2709 testContext.expectedStatusCode = [200];2710 };2711 });2712 it('should process when not providing test context and not marking as performance test.', function (done) {2713 testContext.setupTest();2714 testContext.setupHttpRequest();2715 testContext.setupGetFirstName();2716 testContext.setupGetMiddleName();2717 testContext.setupGetLastName();2718 testContext.setupExpected();2719 new Scenario()2720 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2721 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2722 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2723 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2724 .withHttpRequest(testContext.httpRequestParams)2725 .resShouldBeCalledWith('send', testContext.expectedResponse)2726 .resShouldBeCalledWith('status', testContext.expectedStatusCode)2727 .resDoesReturnSelf('status')2728 .shouldAlwaysBeIgnored('proxyInstance', 'getFirstName', testContext.getFirstNameParams)2729 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2730 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2731 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName3Result)2732 .shouldAlwaysBeIgnored('proxyInstance', 'getMiddleName')2733 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName1Result)2734 .shouldAlwaysBeIgnored('proxyInstance', 'getMiddleName')2735 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName2Result)2736 .shouldAlwaysBeIgnored('proxyInstance', 'getMiddleName')2737 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleName3Result)2738 .shouldAlwaysBeIgnored('proxyInstance', 'getLastName')2739 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName1Result)2740 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName2Params)2741 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName2Result)2742 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastName3Params)2743 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastName3Result)2744 .test(done);2745 });2746 });2747 describe('when ignoring params, it', function () {2748 beforeEach(function () {2749 testContext = {};2750 testContext.setupTest = function () {2751 testContext.entryPointObject = Controller;2752 testContext.entryPointFunction = 'statelessEs6Proxy';2753 testContext.proxyInstance = StatelessEs6Proxy;2754 };2755 testContext.setupHttpRequest = function () {2756 testContext.httpRequest = {2757 params: {2758 personId: '123456789'2759 },2760 query: {2761 homeState: 'IL'2762 }2763 };2764 testContext.httpRequestParams = [testContext.httpRequest];2765 };2766 testContext.setupGetFirstName = function () {2767 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];2768 testContext.getFirstName1Result = random.firstName();2769 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];2770 testContext.getFirstName2Result = random.firstName();2771 };2772 testContext.setupGetMiddleName = function () {2773 testContext.getMiddleNameParams = [constants.IgnoreParam, testContext.getFirstName2Result];2774 testContext.getMiddleNameResult = random.firstName();2775 };2776 testContext.setupGetLastName = function () {2777 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];2778 testContext.getLastNameResult = [undefined, random.lastName()];2779 };2780 testContext.setupExpected = function () {2781 testContext.expectedResponse = [{2782 personId: testContext.httpRequest.params.personId,2783 homeState: testContext.httpRequest.query.homeState,2784 lastName: testContext.getLastNameResult[1]2785 }];2786 testContext.expectedStatusCode = [200];2787 };2788 });2789 it('should should ignore the first param of a mock when the first param is marked to be ignored.', function (done) {2790 testContext.setupTest();2791 testContext.setupHttpRequest();2792 testContext.setupGetFirstName();2793 testContext.setupGetMiddleName();2794 testContext.setupGetLastName();2795 testContext.setupExpected();2796 new Scenario(this)2797 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2798 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2799 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2800 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2801 .withHttpRequest(testContext.httpRequestParams)2802 .resShouldBeCalledWith('send', testContext.expectedResponse)2803 .resShouldBeCalledWith('status', testContext.expectedStatusCode)2804 .resDoesReturnSelf('status')2805 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)2806 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2807 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)2808 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2809 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)2810 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2811 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)2812 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2813 .perf()2814 .test(done);2815 });2816 it('should should ignore all params of a mock when they are marked to be ignored.', function (done) {2817 testContext.setupGetMiddleName = function () {2818 testContext.getMiddleNameParams = [constants.IgnoreParam, constants.IgnoreParam];2819 testContext.getMiddleNameResult = random.firstName();2820 };2821 testContext.setupTest();2822 testContext.setupHttpRequest();2823 testContext.setupGetFirstName();2824 testContext.setupGetMiddleName();2825 testContext.setupGetLastName();2826 testContext.setupExpected();2827 new Scenario(this)2828 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2829 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2830 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2831 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2832 .withHttpRequest(testContext.httpRequestParams)2833 .resShouldBeCalledWith('send', testContext.expectedResponse)2834 .resShouldBeCalledWith('status', testContext.expectedStatusCode)2835 .resDoesReturnSelf('status')2836 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)2837 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2838 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)2839 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2840 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)2841 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2842 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)2843 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2844 .perf()2845 .test(done);2846 });2847 it('should should ignore params in more than one mock when they are marked to be ignored.', function (done) {2848 testContext.setupGetMiddleName = function () {2849 testContext.getMiddleNameParams = [constants.IgnoreParam, constants.IgnoreParam];2850 testContext.getMiddleNameResult = random.firstName();2851 };2852 testContext.setupGetLastName = function () {2853 testContext.getLastNameParams = [testContext.httpRequest.params.personId, constants.IgnoreParam, testContext.getMiddleNameResult];2854 testContext.getLastNameResult = [undefined, random.lastName()];2855 };2856 testContext.setupTest();2857 testContext.setupHttpRequest();2858 testContext.setupGetFirstName();2859 testContext.setupGetMiddleName();2860 testContext.setupGetLastName();2861 testContext.setupExpected();2862 new Scenario(this)2863 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2864 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2865 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2866 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2867 .withHttpRequest(testContext.httpRequestParams)2868 .resShouldBeCalledWith('send', testContext.expectedResponse)2869 .resShouldBeCalledWith('status', testContext.expectedStatusCode)2870 .resDoesReturnSelf('status')2871 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)2872 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2873 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)2874 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2875 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)2876 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2877 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)2878 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2879 .perf()2880 .test(done);2881 });2882 });2883 describe('when using shouldBeCallWithSubset params, it', function () {2884 beforeEach(function () {2885 testContext = {};2886 testContext.setupTest = function () {2887 testContext.entryPointObject = Controller;2888 testContext.entryPointFunction = 'statelessEs6Proxy';2889 testContext.proxyInstance = StatelessEs6Proxy;2890 };2891 testContext.setupHttpRequest = function () {2892 testContext.httpRequest = {2893 params: {2894 personId: {2895 someId: '123456789',2896 anotherId: '123456789'2897 }2898 },2899 query: {2900 homeState: 'IL'2901 }2902 };2903 testContext.httpRequestParams = [testContext.httpRequest];2904 };2905 testContext.setupGetFirstName = function () {2906 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];2907 testContext.getFirstName1Result = random.firstName();2908 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];2909 testContext.getFirstName2Result = random.firstName();2910 };2911 testContext.setupGetMiddleName = function () {2912 testContext.getMiddleNameParams = [constants.IgnoreParam, testContext.getFirstName2Result];2913 testContext.getMiddleNameResult = random.firstName();2914 };2915 testContext.setupGetLastName = function () {2916 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];2917 testContext.getLastNameResult = [undefined, random.lastName()];2918 };2919 testContext.setupExpected = function () {2920 testContext.expectedResponse = [{2921 personId: testContext.httpRequest.params.personId,2922 homeState: testContext.httpRequest.query.homeState,2923 lastName: testContext.getLastNameResult[1]2924 }];2925 testContext.expectedStatusCode = [200];2926 };2927 });2928 it('should pass all tests when using subset comparisons and all values are identical.', function (done) {2929 testContext.setupTest();2930 testContext.setupHttpRequest();2931 testContext.setupGetFirstName();2932 testContext.setupGetMiddleName();2933 testContext.setupGetLastName();2934 testContext.setupExpected();2935 new Scenario(this)2936 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2937 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2938 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2939 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2940 .withHttpRequest(testContext.httpRequestParams)2941 .resShouldBeCalledWithSubset('send', testContext.expectedResponse)2942 .resShouldBeCalledWithSubset('status', testContext.expectedStatusCode)2943 .resDoesReturnSelf('status')2944 .shouldBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstName1Params)2945 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2946 .shouldBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstName2Params)2947 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2948 .shouldBeCalledWithSubset('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)2949 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2950 .shouldBeCalledWithSubset('proxyInstance', 'getLastName', testContext.getLastNameParams)2951 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2952 .test(done);2953 });2954 it('should pass all tests when using subset comparisons and the object is a subset.', function (done) {2955 testContext.setupGetFirstName = function () {2956 const params1 = {2957 someId: testContext.httpRequest.params.personId.someId2958 };2959 const params2 = {2960 anotherId: testContext.httpRequest.params.personId.anotherId2961 };2962 testContext.getFirstName1Params = [params1];2963 testContext.getFirstName1Result = random.firstName();2964 testContext.getFirstName2Params = [params2, testContext.getFirstName1Result];2965 testContext.getFirstName2Result = random.firstName();2966 };2967 testContext.setupTest();2968 testContext.setupHttpRequest();2969 testContext.setupGetFirstName();2970 testContext.setupGetMiddleName();2971 testContext.setupGetLastName();2972 testContext.setupExpected();2973 new Scenario(this)2974 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)2975 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)2976 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)2977 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)2978 .withHttpRequest(testContext.httpRequestParams)2979 .resShouldBeCalledWithSubset('send', testContext.expectedResponse)2980 .resShouldBeCalledWithSubset('status', testContext.expectedStatusCode)2981 .resDoesReturnSelf('status')2982 .shouldBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstName1Params)2983 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)2984 .shouldBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstName2Params)2985 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)2986 .shouldBeCalledWithSubset('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)2987 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)2988 .shouldBeCalledWithSubset('proxyInstance', 'getLastName', testContext.getLastNameParams)2989 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)2990 .test(done);2991 });2992 it('should pass all tests when using subset comparisons and the array is a subset.', function (done) {2993 testContext.setupHttpRequest = function () {2994 testContext.httpRequest = {2995 params: {2996 personId: [2997 {2998 someId: '123456789',2999 anotherId: '123456789'3000 }3001 ]3002 },3003 query: {3004 homeState: 'IL'3005 }3006 };3007 testContext.httpRequestParams = [testContext.httpRequest];3008 };3009 testContext.setupGetFirstName = function () {3010 const params1 = [{3011 someId: testContext.httpRequest.params.personId[0].someId3012 }];3013 const params2 = [{3014 anotherId: testContext.httpRequest.params.personId[0].anotherId3015 }];3016 testContext.getFirstName1Params = [params1];3017 testContext.getFirstName1Result = random.firstName();3018 testContext.getFirstName2Params = [params2, testContext.getFirstName1Result];3019 testContext.getFirstName2Result = random.firstName();3020 };3021 testContext.setupTest();3022 testContext.setupHttpRequest();3023 testContext.setupGetFirstName();3024 testContext.setupGetMiddleName();3025 testContext.setupGetLastName();3026 testContext.setupExpected();3027 new Scenario(this)3028 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)3029 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)3030 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)3031 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)3032 .withHttpRequest(testContext.httpRequestParams)3033 .resShouldBeCalledWithSubset('send', testContext.expectedResponse)3034 .resShouldBeCalledWithSubset('status', testContext.expectedStatusCode)3035 .resDoesReturnSelf('status')3036 .shouldBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstName1Params)3037 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)3038 .shouldBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstName2Params)3039 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)3040 .shouldBeCalledWithSubset('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)3041 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)3042 .shouldBeCalledWithSubset('proxyInstance', 'getLastName', testContext.getLastNameParams)3043 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)3044 .test(done)3045 .catch((err) => done(err));3046 });3047 it('should pass all tests when using subset comparisons for res.send.', function (done) {3048 testContext.setupExpected = function () {3049 testContext.expectedResponse = [{3050 homeState: testContext.httpRequest.query.homeState3051 }];3052 testContext.expectedStatusCode = [200];3053 };3054 testContext.setupTest();3055 testContext.setupHttpRequest();3056 testContext.setupGetFirstName();3057 testContext.setupGetMiddleName();3058 testContext.setupGetLastName();3059 testContext.setupExpected();3060 new Scenario(this)3061 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)3062 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)3063 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)3064 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)3065 .withHttpRequest(testContext.httpRequestParams)3066 .resShouldBeCalledWithSubset('send', testContext.expectedResponse)3067 .resShouldBeCalledWithSubset('status', testContext.expectedStatusCode)3068 .resDoesReturnSelf('status')3069 .shouldBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstName1Params)3070 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)3071 .shouldBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstName2Params)3072 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)3073 .shouldBeCalledWithSubset('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)3074 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)3075 .shouldBeCalledWithSubset('proxyInstance', 'getLastName', testContext.getLastNameParams)3076 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)3077 .test(done)3078 .catch((err) => done(err));3079 });3080 it('should pass all tests when doing a subset comparison for two strings, when one is a subset of the other.', function (done) {3081 testContext.setupGetMiddleName = function () {3082 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result.substring(1, 3)];3083 testContext.getMiddleNameResult = random.firstName();3084 };3085 testContext.setupExpected = function () {3086 testContext.expectedResponse = [{3087 personId: testContext.httpRequest.params.personId,3088 homeState: testContext.httpRequest.query.homeState,3089 lastName: testContext.getLastNameResult[1]3090 }];3091 testContext.expectedErrorMessage = `Maddox Comparison Error (3003): Failed expectation for the second param in mock proxyInstance.getMiddleName, the first time the mock was called ::::: expected '${testContext.getFirstName2Result}' to deeply equal 'SomeWrongValue'`;3092 testContext.expectedStatusCode = [200];3093 };3094 testContext.setupTest();3095 testContext.setupHttpRequest();3096 testContext.setupGetFirstName();3097 testContext.setupGetMiddleName();3098 testContext.setupGetLastName();3099 testContext.setupExpected();3100 new Scenario(this)3101 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)3102 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)3103 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)3104 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)3105 .withHttpRequest(testContext.httpRequestParams)3106 .resShouldBeCalledWithSubset('send', testContext.expectedResponse)3107 .resShouldBeCalledWithSubset('status', testContext.expectedStatusCode)3108 .resDoesReturnSelf('status')3109 .shouldBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstName1Params)3110 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)3111 .shouldBeCalledWithSubset('proxyInstance', 'getFirstName', testContext.getFirstName2Params)3112 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)3113 .shouldBeCalledWithSubset('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)3114 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)3115 .shouldBeCalledWithSubset('proxyInstance', 'getLastName', testContext.getLastNameParams)3116 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)3117 .test(done)3118 .catch((err) => done(err));3119 });3120 });...

Full Screen

Full Screen

http-req-unit-test.js

Source:http-req-unit-test.js Github

copy

Full Screen

1const Maddox = require('../../lib/index'), // require("maddox");2 random = require('../random'),3 Controller = require('../testable/modules/test-module/from-http-req-controller'),4 testConstants = require('../test-constants'),5 StatefulSingletonProxy = require('../testable/proxies/stateful-singleton-proxy');6const Scenario = Maddox.functional.HttpReqScenario;7describe('Given the HttpReqScenario', function () {8 let testContext;9 describe('when using the HttpReqScenario, it', function () {10 beforeEach(function () {11 testContext = {};12 testContext.setupTest = function () {13 testContext.entryPointObject = Controller;14 testContext.entryPointFunction = 'statefulSingletonProxy';15 testContext.proxyInstance = StatefulSingletonProxy.getInstance();16 };17 testContext.setupHttpRequest = function () {18 testContext.httpRequest = {19 params: {20 personId: '123456789'21 },22 query: {23 homeState: 'IL'24 }25 };26 testContext.httpRequestParams = [testContext.httpRequest];27 };28 testContext.setupGetFirstName = function () {29 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];30 testContext.getFirstName1Result = random.firstName();31 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];32 testContext.getFirstName2Result = random.firstName();33 };34 testContext.setupGetMiddleName = function () {35 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];36 testContext.getMiddleNameResult = random.firstName();37 };38 testContext.setupGetLastName = function () {39 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];40 testContext.getLastNameResult = [undefined, random.lastName()];41 };42 testContext.setupExpected = function () {43 testContext.expectedResponse = [{44 personId: testContext.httpRequest.params.personId,45 homeState: testContext.httpRequest.query.homeState,46 lastName: testContext.getLastNameResult[1]47 }];48 testContext.expectedStatusCode = [200];49 };50 });51 it('should handle a successful request.', function (done) {52 testContext.setupTest();53 testContext.setupHttpRequest();54 testContext.setupGetFirstName();55 testContext.setupGetMiddleName();56 testContext.setupGetLastName();57 testContext.setupExpected();58 new Scenario(this)59 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)60 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)61 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)62 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)63 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)64 .withHttpRequest(testContext.httpRequestParams)65 .resShouldBeCalledWith('send', testContext.expectedResponse)66 .resShouldBeCalledWith('status', testContext.expectedStatusCode)67 .resDoesReturnSelf('status')68 .shouldBeCalledWith('StatefulSingletonProxy', 'getInstance', Maddox.constants.EmptyParameters)69 .doesReturn('StatefulSingletonProxy', 'getInstance', testContext.proxyInstance)70 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)71 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)72 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)73 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)74 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)75 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)76 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)77 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)78 .perf()79 .test(done);80 });81 it('should handle a checked exception.', function (done) {82 testContext.setupHttpRequest = function () {83 testContext.httpRequest = {84 params: {},85 query: {86 homeState: 'IL'87 }88 };89 testContext.httpRequestParams = [testContext.httpRequest];90 };91 testContext.setupExpected = function () {92 testContext.expectedResponse = [testConstants.MissingPersonIdParam];93 testContext.expectedStatusCode = [404];94 };95 testContext.setupTest();96 testContext.setupHttpRequest();97 testContext.setupGetFirstName();98 testContext.setupGetMiddleName();99 testContext.setupGetLastName();100 testContext.setupExpected();101 new Scenario(this)102 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)103 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)104 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)105 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)106 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)107 .withHttpRequest(testContext.httpRequestParams)108 .resShouldBeCalledWith('send', testContext.expectedResponse)109 .resShouldBeCalledWith('status', testContext.expectedStatusCode)110 .resDoesReturnSelf('status')111 .test(done);112 });113 });114 describe('when initiating an async process and using a finisher function, it', function () {115 beforeEach(function () {116 testContext = {};117 testContext.setupTest = function () {118 testContext.entryPointObject = Controller;119 testContext.entryPointFunction = 'initiateAsyncProcessing';120 testContext.proxyInstance = StatefulSingletonProxy.getInstance();121 };122 testContext.setupHttpRequest = function () {123 testContext.httpRequest = {124 params: {125 personId: '123456789'126 },127 query: {128 homeState: 'IL'129 }130 };131 testContext.httpRequestParams = [testContext.httpRequest];132 };133 testContext.setupGetFirstName = function () {134 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];135 testContext.getFirstName1Result = random.firstName();136 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];137 testContext.getFirstName2Result = random.firstName();138 };139 testContext.setupGetMiddleName = function () {140 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];141 testContext.getMiddleNameResult = random.firstName();142 };143 testContext.setupGetLastName = function () {144 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];145 testContext.getLastNameResult = [undefined, random.lastName()];146 };147 testContext.setupExpected = function () {148 testContext.expectedResponse = [{149 result: 'OK'150 }];151 testContext.expectedStatusCode = [200];152 };153 });154 it('should still test HTTP Response if it happens before the finisher function is executed.', function (done) {155 testContext.setupTest();156 testContext.setupHttpRequest();157 testContext.setupGetFirstName();158 testContext.setupGetMiddleName();159 testContext.setupGetLastName();160 testContext.setupExpected();161 new Scenario(this)162 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)163 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)164 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)165 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)166 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)167 .withHttpRequest(testContext.httpRequestParams)168 .withTestFinisherFunction('proxyInstance', 'getLastName', 0)169 .resShouldBeCalledWith('send', testContext.expectedResponse)170 .resShouldBeCalledWith('status', testContext.expectedStatusCode)171 .resDoesReturnSelf('status')172 .shouldBeCalledWith('StatefulSingletonProxy', 'getInstance', Maddox.constants.EmptyParameters)173 .doesReturn('StatefulSingletonProxy', 'getInstance', testContext.proxyInstance)174 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)175 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)176 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)177 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)178 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)179 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)180 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)181 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)182 .test(done);183 });184 });185 describe('when using the specialResponseFunctionality, it', function () {186 beforeEach(function () {187 testContext = {};188 testContext.setupTest = function () {189 testContext.entryPointObject = Controller;190 testContext.entryPointFunction = 'specialResponseFunctionality';191 testContext.proxyInstance = StatefulSingletonProxy.getInstance();192 };193 testContext.setupHttpRequest = function () {194 testContext.httpRequest = {195 params: {196 personId: '123456789'197 },198 query: {199 homeState: 'IL'200 }201 };202 testContext.httpRequestParams = [testContext.httpRequest];203 };204 testContext.setupGetFirstName = function () {205 testContext.getFirstName1Params = [testContext.httpRequest.params.personId];206 testContext.getFirstName1Result = random.firstName();207 testContext.getFirstName2Params = [testContext.httpRequest.params.personId, testContext.getFirstName1Result];208 testContext.getFirstName2Result = random.firstName();209 };210 testContext.setupGetMiddleName = function () {211 testContext.getMiddleNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result];212 testContext.getMiddleNameResult = random.firstName();213 };214 testContext.setupGetLastName = function () {215 testContext.getLastNameParams = [testContext.httpRequest.params.personId, testContext.getFirstName2Result, testContext.getMiddleNameResult];216 testContext.getLastNameResult = [undefined, random.lastName()];217 };218 testContext.setupHttpHeaders = function () {219 testContext.headerKey1 = 'someHeader1';220 testContext.headerValue1 = testContext.httpRequest.params.personId;221 testContext.headerKey2 = 'someHeader2';222 testContext.headerValue2 = testContext.httpRequest.query.homeState;223 testContext.headerKey3 = 'someHeader3';224 testContext.headerValue3 = testContext.httpRequest.query.homeState;225 };226 testContext.setupExpected = function () {227 testContext.someResParams1 = [testContext.getLastNameResult[1]];228 testContext.someResResponse1 = random.uniqueId();229 testContext.someResParams2 = [testContext.getLastNameResult[1]];230 testContext.someResResponse2 = random.uniqueId();231 testContext.expectedResponse = [{232 personId: testContext.httpRequest.params.personId,233 homeState: testContext.httpRequest.query.homeState,234 lastName: testContext.getLastNameResult[1],235 someHeaderResponse1: testContext.someResResponse1,236 someHeaderResponse2: testContext.someResResponse2237 }];238 testContext.expectedStatusCode = [200];239 };240 });241 it('should use \'resShouldContainerHeader\' and \'resDoesReturn\'.', function (done) {242 testContext.setupTest();243 testContext.setupHttpRequest();244 testContext.setupGetFirstName();245 testContext.setupGetMiddleName();246 testContext.setupGetLastName();247 testContext.setupHttpHeaders();248 testContext.setupExpected();249 new Scenario(this)250 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)251 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)252 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)253 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)254 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)255 .withHttpRequest(testContext.httpRequestParams)256 .resShouldBeCalledWith('send', testContext.expectedResponse)257 .resShouldBeCalledWith('someResFunction', testContext.someResParams1)258 .resDoesReturn('someResFunction', testContext.someResResponse1)259 .resShouldBeCalledWith('someResFunction', testContext.someResParams2)260 .resDoesReturn('someResFunction', testContext.someResResponse2)261 .resShouldBeCalledWith('status', testContext.expectedStatusCode)262 .resDoesReturnSelf('status')263 .resShouldContainHeader(testContext.headerKey1, testContext.headerValue1, 'set')264 .resShouldContainHeader(testContext.headerKey2, testContext.headerValue2) // Should default to set265 .resShouldContainHeader(testContext.headerKey3, testContext.headerValue3, 'fakeHeaderFunction')266 .shouldBeCalledWith('StatefulSingletonProxy', 'getInstance', Maddox.constants.EmptyParameters)267 .doesReturn('StatefulSingletonProxy', 'getInstance', testContext.proxyInstance)268 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)269 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)270 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)271 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)272 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)273 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)274 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)275 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)276 .test(done);277 });278 it('should use \'resDoesAlwaysReturn\' and \'resShouldAlwaysBeCalledWith\'.', function (done) {279 testContext.setupExpected = function () {280 testContext.someResParams1 = [testContext.getLastNameResult[1]];281 testContext.someResResponse1 = random.uniqueId();282 testContext.someResParams2 = [testContext.getLastNameResult[1]];283 testContext.someResResponse2 = random.uniqueId();284 testContext.expectedResponse = [{285 personId: testContext.httpRequest.params.personId,286 homeState: testContext.httpRequest.query.homeState,287 lastName: testContext.getLastNameResult[1],288 someHeaderResponse1: testContext.someResResponse1,289 someHeaderResponse2: testContext.someResResponse1290 }];291 testContext.expectedStatusCode = [200];292 };293 testContext.setupTest();294 testContext.setupHttpRequest();295 testContext.setupGetFirstName();296 testContext.setupGetMiddleName();297 testContext.setupGetLastName();298 testContext.setupHttpHeaders();299 testContext.setupExpected();300 new Scenario(this)301 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)302 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)303 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)304 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)305 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)306 .withHttpRequest(testContext.httpRequestParams)307 .resShouldBeCalledWith('send', testContext.expectedResponse)308 .resShouldAlwaysBeCalledWith('someResFunction', testContext.someResParams1)309 .resDoesAlwaysReturn('someResFunction', testContext.someResResponse1)310 .resShouldBeCalledWith('status', testContext.expectedStatusCode)311 .resDoesReturnSelf('status')312 .resShouldContainHeader(testContext.headerKey1, testContext.headerValue1, 'set')313 .resShouldContainHeader(testContext.headerKey2, testContext.headerValue2) // Should default to set314 .resShouldContainHeader(testContext.headerKey3, testContext.headerValue3, 'fakeHeaderFunction')315 .shouldBeCalledWith('StatefulSingletonProxy', 'getInstance', Maddox.constants.EmptyParameters)316 .doesReturn('StatefulSingletonProxy', 'getInstance', testContext.proxyInstance)317 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)318 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)319 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)320 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)321 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)322 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)323 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)324 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)325 .test(done);326 });327 it('should use \'resDoesAlwaysReturn\' by itself.', function (done) {328 testContext.setupExpected = function () {329 testContext.someResParams1 = [testContext.getLastNameResult[1]];330 testContext.someResResponse1 = random.uniqueId();331 testContext.someResParams2 = [testContext.getLastNameResult[1]];332 testContext.someResResponse2 = random.uniqueId();333 testContext.expectedResponse = [{334 personId: testContext.httpRequest.params.personId,335 homeState: testContext.httpRequest.query.homeState,336 lastName: testContext.getLastNameResult[1],337 someHeaderResponse1: testContext.someResResponse1,338 someHeaderResponse2: testContext.someResResponse1339 }];340 testContext.expectedStatusCode = [200];341 };342 testContext.setupTest();343 testContext.setupHttpRequest();344 testContext.setupGetFirstName();345 testContext.setupGetMiddleName();346 testContext.setupGetLastName();347 testContext.setupHttpHeaders();348 testContext.setupExpected();349 new Scenario(this)350 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)351 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)352 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)353 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)354 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)355 .withHttpRequest(testContext.httpRequestParams)356 .resShouldBeCalledWith('send', testContext.expectedResponse)357 .resShouldBeCalledWith('someResFunction', testContext.someResParams1)358 .resShouldBeCalledWith('someResFunction', testContext.someResParams2)359 .resDoesAlwaysReturn('someResFunction', testContext.someResResponse1)360 .resShouldBeCalledWith('status', testContext.expectedStatusCode)361 .resDoesReturnSelf('status')362 .resShouldContainHeader(testContext.headerKey1, testContext.headerValue1, 'set')363 .resShouldContainHeader(testContext.headerKey2, testContext.headerValue2) // Should default to set364 .resShouldContainHeader(testContext.headerKey3, testContext.headerValue3, 'fakeHeaderFunction')365 .shouldBeCalledWith('StatefulSingletonProxy', 'getInstance', Maddox.constants.EmptyParameters)366 .doesReturn('StatefulSingletonProxy', 'getInstance', testContext.proxyInstance)367 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)368 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)369 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)370 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)371 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)372 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)373 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)374 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)375 .test(done);376 });377 it('should use \'resShouldAlwaysBeCalledWith\' by itself.', function (done) {378 testContext.setupTest();379 testContext.setupHttpRequest();380 testContext.setupGetFirstName();381 testContext.setupGetMiddleName();382 testContext.setupGetLastName();383 testContext.setupHttpHeaders();384 testContext.setupExpected();385 new Scenario(this)386 .mockThisFunction('StatefulSingletonProxy', 'getInstance', StatefulSingletonProxy)387 .mockThisFunction('proxyInstance', 'getFirstName', testContext.proxyInstance)388 .mockThisFunction('proxyInstance', 'getMiddleName', testContext.proxyInstance)389 .mockThisFunction('proxyInstance', 'getLastName', testContext.proxyInstance)390 .withEntryPoint(testContext.entryPointObject, testContext.entryPointFunction)391 .withHttpRequest(testContext.httpRequestParams)392 .resShouldBeCalledWith('send', testContext.expectedResponse)393 .resShouldAlwaysBeCalledWith('someResFunction', testContext.someResParams1)394 .resDoesReturn('someResFunction', testContext.someResResponse1)395 .resDoesReturn('someResFunction', testContext.someResResponse2)396 .resShouldBeCalledWith('status', testContext.expectedStatusCode)397 .resDoesReturnSelf('status')398 .resShouldContainHeader(testContext.headerKey1, testContext.headerValue1, 'set')399 .resShouldContainHeader(testContext.headerKey2, testContext.headerValue2) // Should default to set400 .resShouldContainHeader(testContext.headerKey3, testContext.headerValue3, 'fakeHeaderFunction')401 .shouldBeCalledWith('StatefulSingletonProxy', 'getInstance', Maddox.constants.EmptyParameters)402 .doesReturn('StatefulSingletonProxy', 'getInstance', testContext.proxyInstance)403 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName1Params)404 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName1Result)405 .shouldBeCalledWith('proxyInstance', 'getFirstName', testContext.getFirstName2Params)406 .doesReturnWithPromise('proxyInstance', 'getFirstName', testContext.getFirstName2Result)407 .shouldBeCalledWith('proxyInstance', 'getMiddleName', testContext.getMiddleNameParams)408 .doesReturn('proxyInstance', 'getMiddleName', testContext.getMiddleNameResult)409 .shouldBeCalledWith('proxyInstance', 'getLastName', testContext.getLastNameParams)410 .doesReturnWithCallback('proxyInstance', 'getLastName', testContext.getLastNameResult)411 .test(done);412 });413 });...

Full Screen

Full Screen

drop_down_spec.js

Source:drop_down_spec.js Github

copy

Full Screen

1import DropDown from '~/droplab/drop_down';2import utils from '~/droplab/utils';3import { SELECTED_CLASS } from '~/droplab/constants';4describe('DropLab DropDown', () => {5 let testContext;6 beforeEach(() => {7 testContext = {};8 });9 describe('class constructor', () => {10 beforeEach(() => {11 jest.spyOn(DropDown.prototype, 'getItems').mockImplementation(() => {});12 jest.spyOn(DropDown.prototype, 'initTemplateString').mockImplementation(() => {});13 jest.spyOn(DropDown.prototype, 'addEvents').mockImplementation(() => {});14 testContext.list = { innerHTML: 'innerHTML' };15 testContext.dropdown = new DropDown(testContext.list);16 });17 it('sets the .hidden property to true', () => {18 expect(testContext.dropdown.hidden).toBe(true);19 });20 it('sets the .list property', () => {21 expect(testContext.dropdown.list).toBe(testContext.list);22 });23 it('calls .getItems', () => {24 expect(DropDown.prototype.getItems).toHaveBeenCalled();25 });26 it('calls .initTemplateString', () => {27 expect(DropDown.prototype.initTemplateString).toHaveBeenCalled();28 });29 it('calls .addEvents', () => {30 expect(DropDown.prototype.addEvents).toHaveBeenCalled();31 });32 it('sets the .initialState property to the .list.innerHTML', () => {33 expect(testContext.dropdown.initialState).toBe(testContext.list.innerHTML);34 });35 describe('if the list argument is a string', () => {36 beforeEach(() => {37 testContext.element = {};38 testContext.selector = '.selector';39 jest.spyOn(Document.prototype, 'querySelector').mockReturnValue(testContext.element);40 testContext.dropdown = new DropDown(testContext.selector);41 });42 it('calls .querySelector with the selector string', () => {43 expect(Document.prototype.querySelector).toHaveBeenCalledWith(testContext.selector);44 });45 it('sets the .list property element', () => {46 expect(testContext.dropdown.list).toBe(testContext.element);47 });48 });49 });50 describe('getItems', () => {51 beforeEach(() => {52 testContext.list = { querySelectorAll: () => {} };53 testContext.dropdown = { list: testContext.list };54 testContext.nodeList = [];55 jest.spyOn(testContext.list, 'querySelectorAll').mockReturnValue(testContext.nodeList);56 testContext.getItems = DropDown.prototype.getItems.call(testContext.dropdown);57 });58 it('calls .querySelectorAll with a list item query', () => {59 expect(testContext.list.querySelectorAll).toHaveBeenCalledWith('li');60 });61 it('sets the .items property to the returned list items', () => {62 expect(testContext.dropdown.items).toEqual(expect.any(Array));63 });64 it('returns the .items', () => {65 expect(testContext.getItems).toEqual(expect.any(Array));66 });67 });68 describe('initTemplateString', () => {69 beforeEach(() => {70 testContext.items = [{ outerHTML: '<a></a>' }, { outerHTML: '<img>' }];71 testContext.dropdown = { items: testContext.items };72 DropDown.prototype.initTemplateString.call(testContext.dropdown);73 });74 it('should set .templateString to the last items .outerHTML', () => {75 expect(testContext.dropdown.templateString).toBe(testContext.items[1].outerHTML);76 });77 it('should not set .templateString to a non-last items .outerHTML', () => {78 expect(testContext.dropdown.templateString).not.toBe(testContext.items[0].outerHTML);79 });80 describe('if .items is not set', () => {81 beforeEach(() => {82 testContext.dropdown = { getItems: () => {} };83 jest.spyOn(testContext.dropdown, 'getItems').mockReturnValue([]);84 DropDown.prototype.initTemplateString.call(testContext.dropdown);85 });86 it('should call .getItems', () => {87 expect(testContext.dropdown.getItems).toHaveBeenCalled();88 });89 });90 describe('if items array is empty', () => {91 beforeEach(() => {92 testContext.dropdown = { items: [] };93 DropDown.prototype.initTemplateString.call(testContext.dropdown);94 });95 it('should set .templateString to an empty string', () => {96 expect(testContext.dropdown.templateString).toBe('');97 });98 });99 });100 describe('clickEvent', () => {101 beforeEach(() => {102 testContext.classList = {103 contains: jest.fn(),104 };105 testContext.list = { dispatchEvent: () => {} };106 testContext.dropdown = {107 hideOnClick: true,108 hide: () => {},109 list: testContext.list,110 addSelectedClass: () => {},111 };112 testContext.event = {113 preventDefault: () => {},114 target: {115 classList: testContext.classList,116 closest: () => null,117 },118 };119 testContext.dummyListItem = document.createElement('li');120 jest.spyOn(testContext.event.target, 'closest').mockImplementation(selector => {121 if (selector === 'li') {122 return testContext.dummyListItem;123 }124 return null;125 });126 jest.spyOn(testContext.dropdown, 'hide').mockImplementation(() => {});127 jest.spyOn(testContext.dropdown, 'addSelectedClass').mockImplementation(() => {});128 jest.spyOn(testContext.list, 'dispatchEvent').mockImplementation(() => {});129 jest.spyOn(testContext.event, 'preventDefault').mockImplementation(() => {});130 window.CustomEvent = jest.fn();131 testContext.classList.contains.mockReturnValue(false);132 });133 describe('normal click event', () => {134 beforeEach(() => {135 DropDown.prototype.clickEvent.call(testContext.dropdown, testContext.event);136 });137 it('should call event.target.closest', () => {138 expect(testContext.event.target.closest).toHaveBeenCalledWith('.droplab-item-ignore');139 expect(testContext.event.target.closest).toHaveBeenCalledWith('li');140 });141 it('should call addSelectedClass', () => {142 expect(testContext.dropdown.addSelectedClass).toHaveBeenCalledWith(143 testContext.dummyListItem,144 );145 });146 it('should call .preventDefault', () => {147 expect(testContext.event.preventDefault).toHaveBeenCalled();148 });149 it('should call .hide', () => {150 expect(testContext.dropdown.hide).toHaveBeenCalled();151 });152 it('should construct CustomEvent', () => {153 expect(window.CustomEvent).toHaveBeenCalledWith('click.dl', expect.any(Object));154 });155 it('should call .dispatchEvent with the customEvent', () => {156 expect(testContext.list.dispatchEvent).toHaveBeenCalledWith({});157 });158 });159 describe('if the target is a UL element', () => {160 beforeEach(() => {161 testContext.event.target = document.createElement('ul');162 jest.spyOn(testContext.event.target, 'closest').mockImplementation(() => {});163 });164 it('should return immediately', () => {165 DropDown.prototype.clickEvent.call(testContext.dropdown, testContext.event);166 expect(testContext.event.target.closest).not.toHaveBeenCalled();167 expect(testContext.dropdown.addSelectedClass).not.toHaveBeenCalled();168 });169 });170 describe('if the target has the droplab-item-ignore class', () => {171 beforeEach(() => {172 testContext.ignoredButton = document.createElement('button');173 testContext.ignoredButton.classList.add('droplab-item-ignore');174 testContext.event.target = testContext.ignoredButton;175 jest.spyOn(testContext.ignoredButton, 'closest');176 });177 it('does not select element', () => {178 DropDown.prototype.clickEvent.call(testContext.dropdown, testContext.event);179 expect(testContext.ignoredButton.closest.mock.calls.length).toBe(1);180 expect(testContext.ignoredButton.closest).toHaveBeenCalledWith('.droplab-item-ignore');181 expect(testContext.dropdown.addSelectedClass).not.toHaveBeenCalled();182 });183 });184 describe('if no selected element exists', () => {185 beforeEach(() => {186 testContext.event.preventDefault.mockReset();187 testContext.dummyListItem = null;188 });189 it('should return before .preventDefault is called', () => {190 DropDown.prototype.clickEvent.call(testContext.dropdown, testContext.event);191 expect(testContext.event.preventDefault).not.toHaveBeenCalled();192 expect(testContext.dropdown.addSelectedClass).not.toHaveBeenCalled();193 });194 });195 describe('if hideOnClick is false', () => {196 beforeEach(() => {197 testContext.dropdown.hideOnClick = false;198 testContext.dropdown.hide.mockReset();199 });200 it('should not call .hide', () => {201 DropDown.prototype.clickEvent.call(testContext.dropdown, testContext.event);202 expect(testContext.dropdown.hide).not.toHaveBeenCalled();203 });204 });205 });206 describe('addSelectedClass', () => {207 beforeEach(() => {208 testContext.items = Array(4).forEach((item, i) => {209 testContext.items[i] = { classList: { add: () => {} } };210 jest.spyOn(testContext.items[i].classList, 'add').mockImplementation(() => {});211 });212 testContext.selected = { classList: { add: () => {} } };213 testContext.dropdown = { removeSelectedClasses: () => {} };214 jest.spyOn(testContext.dropdown, 'removeSelectedClasses').mockImplementation(() => {});215 jest.spyOn(testContext.selected.classList, 'add').mockImplementation(() => {});216 DropDown.prototype.addSelectedClass.call(testContext.dropdown, testContext.selected);217 });218 it('should call .removeSelectedClasses', () => {219 expect(testContext.dropdown.removeSelectedClasses).toHaveBeenCalled();220 });221 it('should call .classList.add', () => {222 expect(testContext.selected.classList.add).toHaveBeenCalledWith(SELECTED_CLASS);223 });224 });225 describe('removeSelectedClasses', () => {226 beforeEach(() => {227 testContext.items = [...Array(4)];228 testContext.items.forEach((item, i) => {229 testContext.items[i] = { classList: { add: jest.fn(), remove: jest.fn() } };230 });231 testContext.dropdown = { items: testContext.items };232 DropDown.prototype.removeSelectedClasses.call(testContext.dropdown);233 });234 it('should call .classList.remove for all items', () => {235 testContext.items.forEach((_, i) => {236 expect(testContext.items[i].classList.remove).toHaveBeenCalledWith(SELECTED_CLASS);237 });238 });239 describe('if .items is not set', () => {240 beforeEach(() => {241 testContext.dropdown = { getItems: () => {} };242 jest.spyOn(testContext.dropdown, 'getItems').mockReturnValue([]);243 DropDown.prototype.removeSelectedClasses.call(testContext.dropdown);244 });245 it('should call .getItems', () => {246 expect(testContext.dropdown.getItems).toHaveBeenCalled();247 });248 });249 });250 describe('addEvents', () => {251 beforeEach(() => {252 testContext.list = {253 addEventListener: () => {},254 querySelectorAll: () => [],255 };256 testContext.dropdown = {257 list: testContext.list,258 clickEvent: () => {},259 closeDropdown: () => {},260 eventWrapper: {},261 };262 });263 it('should call .addEventListener', () => {264 jest.spyOn(testContext.list, 'addEventListener').mockImplementation(() => {});265 DropDown.prototype.addEvents.call(testContext.dropdown);266 expect(testContext.list.addEventListener).toHaveBeenCalledWith('click', expect.any(Function));267 expect(testContext.list.addEventListener).toHaveBeenCalledWith('keyup', expect.any(Function));268 });269 });270 describe('setData', () => {271 beforeEach(() => {272 testContext.dropdown = { render: () => {} };273 testContext.data = ['data'];274 jest.spyOn(testContext.dropdown, 'render').mockImplementation(() => {});275 DropDown.prototype.setData.call(testContext.dropdown, testContext.data);276 });277 it('should set .data', () => {278 expect(testContext.dropdown.data).toBe(testContext.data);279 });280 it('should call .render with the .data', () => {281 expect(testContext.dropdown.render).toHaveBeenCalledWith(testContext.data);282 });283 });284 describe('addData', () => {285 beforeEach(() => {286 testContext.dropdown = { render: () => {}, data: ['data1'] };287 testContext.data = ['data2'];288 jest.spyOn(testContext.dropdown, 'render').mockImplementation(() => {});289 jest.spyOn(Array.prototype, 'concat');290 DropDown.prototype.addData.call(testContext.dropdown, testContext.data);291 });292 it('should call .concat with data', () => {293 expect(Array.prototype.concat).toHaveBeenCalledWith(testContext.data);294 });295 it('should set .data with concatination', () => {296 expect(testContext.dropdown.data).toStrictEqual(['data1', 'data2']);297 });298 it('should call .render with the .data', () => {299 expect(testContext.dropdown.render).toHaveBeenCalledWith(['data1', 'data2']);300 });301 describe('if .data is undefined', () => {302 beforeEach(() => {303 testContext.dropdown = { render: () => {}, data: undefined };304 testContext.data = ['data2'];305 jest.spyOn(testContext.dropdown, 'render').mockImplementation(() => {});306 DropDown.prototype.addData.call(testContext.dropdown, testContext.data);307 });308 it('should set .data with concatination', () => {309 expect(testContext.dropdown.data).toStrictEqual(['data2']);310 });311 });312 });313 describe('render', () => {314 beforeEach(() => {315 testContext.renderableList = {};316 testContext.list = {317 querySelector: q => {318 if (q === '.filter-dropdown-loading') {319 return false;320 }321 return testContext.renderableList;322 },323 dispatchEvent: () => {},324 };325 testContext.dropdown = { renderChildren: () => {}, list: testContext.list };326 testContext.data = [0, 1];327 testContext.customEvent = {};328 jest.spyOn(testContext.dropdown, 'renderChildren').mockImplementation(data => data);329 jest.spyOn(testContext.list, 'dispatchEvent').mockImplementation(() => {});330 jest.spyOn(testContext.data, 'map');331 jest.spyOn(window, 'CustomEvent').mockReturnValue(testContext.customEvent);332 DropDown.prototype.render.call(testContext.dropdown, testContext.data);333 });334 it('should call .map', () => {335 expect(testContext.data.map).toHaveBeenCalledWith(expect.any(Function));336 });337 it('should call .renderChildren for each data item', () => {338 expect(testContext.dropdown.renderChildren.mock.calls.length).toBe(testContext.data.length);339 });340 it('sets the renderableList .innerHTML', () => {341 expect(testContext.renderableList.innerHTML).toBe('01');342 });343 it('should call render.dl', () => {344 expect(window.CustomEvent).toHaveBeenCalledWith('render.dl', expect.any(Object));345 });346 it('should call dispatchEvent with the customEvent', () => {347 expect(testContext.list.dispatchEvent).toHaveBeenCalledWith(testContext.customEvent);348 });349 describe('if no data argument is passed', () => {350 beforeEach(() => {351 testContext.data.map.mockReset();352 testContext.dropdown.renderChildren.mockReset();353 DropDown.prototype.render.call(testContext.dropdown, undefined);354 });355 it('should not call .map', () => {356 expect(testContext.data.map).not.toHaveBeenCalled();357 });358 it('should not call .renderChildren', () => {359 expect(testContext.dropdown.renderChildren).not.toHaveBeenCalled();360 });361 });362 describe('if no dynamic list is present', () => {363 beforeEach(() => {364 testContext.list = { querySelector: () => {}, dispatchEvent: () => {} };365 testContext.dropdown = { renderChildren: () => {}, list: testContext.list };366 testContext.data = [0, 1];367 jest.spyOn(testContext.dropdown, 'renderChildren').mockImplementation(data => data);368 jest.spyOn(testContext.list, 'querySelector').mockImplementation(() => {});369 jest.spyOn(testContext.data, 'map');370 DropDown.prototype.render.call(testContext.dropdown, testContext.data);371 });372 it('sets the .list .innerHTML', () => {373 expect(testContext.list.innerHTML).toBe('01');374 });375 });376 });377 describe('renderChildren', () => {378 beforeEach(() => {379 testContext.templateString = 'templateString';380 testContext.dropdown = { templateString: testContext.templateString };381 testContext.data = { droplab_hidden: true };382 testContext.html = 'html';383 testContext.template = { firstChild: { outerHTML: 'outerHTML', style: {} } };384 jest.spyOn(utils, 'template').mockReturnValue(testContext.html);385 jest.spyOn(document, 'createElement').mockReturnValue(testContext.template);386 jest.spyOn(DropDown, 'setImagesSrc').mockImplementation(() => {});387 testContext.renderChildren = DropDown.prototype.renderChildren.call(388 testContext.dropdown,389 testContext.data,390 );391 });392 it('should call utils.t with .templateString and data', () => {393 expect(utils.template).toHaveBeenCalledWith(testContext.templateString, testContext.data);394 });395 it('should call document.createElement', () => {396 expect(document.createElement).toHaveBeenCalledWith('div');397 });398 it('should set the templates .innerHTML to the HTML', () => {399 expect(testContext.template.innerHTML).toBe(testContext.html);400 });401 it('should call .setImagesSrc with the template', () => {402 expect(DropDown.setImagesSrc).toHaveBeenCalledWith(testContext.template);403 });404 it('should set the template display to none', () => {405 expect(testContext.template.firstChild.style.display).toBe('none');406 });407 it('should return the templates .firstChild.outerHTML', () => {408 expect(testContext.renderChildren).toBe(testContext.template.firstChild.outerHTML);409 });410 describe('if droplab_hidden is false', () => {411 beforeEach(() => {412 testContext.data = { droplab_hidden: false };413 testContext.renderChildren = DropDown.prototype.renderChildren.call(414 testContext.dropdown,415 testContext.data,416 );417 });418 it('should set the template display to block', () => {419 expect(testContext.template.firstChild.style.display).toBe('block');420 });421 });422 });423 describe('setImagesSrc', () => {424 beforeEach(() => {425 testContext.template = { querySelectorAll: () => {} };426 jest.spyOn(testContext.template, 'querySelectorAll').mockReturnValue([]);427 DropDown.setImagesSrc(testContext.template);428 });429 it('should call .querySelectorAll', () => {430 expect(testContext.template.querySelectorAll).toHaveBeenCalledWith('img[data-src]');431 });432 });433 describe('show', () => {434 beforeEach(() => {435 testContext.list = { style: {} };436 testContext.dropdown = { list: testContext.list, hidden: true };437 DropDown.prototype.show.call(testContext.dropdown);438 });439 it('it should set .list display to block', () => {440 expect(testContext.list.style.display).toBe('block');441 });442 it('it should set .hidden to false', () => {443 expect(testContext.dropdown.hidden).toBe(false);444 });445 describe('if .hidden is false', () => {446 beforeEach(() => {447 testContext.list = { style: {} };448 testContext.dropdown = { list: testContext.list, hidden: false };449 testContext.show = DropDown.prototype.show.call(testContext.dropdown);450 });451 it('should return undefined', () => {452 expect(testContext.show).toBeUndefined();453 });454 it('should not set .list display to block', () => {455 expect(testContext.list.style.display).not.toBe('block');456 });457 });458 });459 describe('hide', () => {460 beforeEach(() => {461 testContext.list = { style: {} };462 testContext.dropdown = { list: testContext.list };463 DropDown.prototype.hide.call(testContext.dropdown);464 });465 it('it should set .list display to none', () => {466 expect(testContext.list.style.display).toBe('none');467 });468 it('it should set .hidden to true', () => {469 expect(testContext.dropdown.hidden).toBe(true);470 });471 });472 describe('toggle', () => {473 beforeEach(() => {474 testContext.hidden = true;475 testContext.dropdown = { hidden: testContext.hidden, show: () => {}, hide: () => {} };476 jest.spyOn(testContext.dropdown, 'show').mockImplementation(() => {});477 jest.spyOn(testContext.dropdown, 'hide').mockImplementation(() => {});478 DropDown.prototype.toggle.call(testContext.dropdown);479 });480 it('should call .show', () => {481 expect(testContext.dropdown.show).toHaveBeenCalled();482 });483 describe('if .hidden is false', () => {484 beforeEach(() => {485 testContext.hidden = false;486 testContext.dropdown = { hidden: testContext.hidden, show: () => {}, hide: () => {} };487 jest.spyOn(testContext.dropdown, 'show').mockImplementation(() => {});488 jest.spyOn(testContext.dropdown, 'hide').mockImplementation(() => {});489 DropDown.prototype.toggle.call(testContext.dropdown);490 });491 it('should call .hide', () => {492 expect(testContext.dropdown.hide).toHaveBeenCalled();493 });494 });495 });496 describe('destroy', () => {497 beforeEach(() => {498 testContext.list = { removeEventListener: () => {} };499 testContext.eventWrapper = { clickEvent: 'clickEvent' };500 testContext.dropdown = {501 list: testContext.list,502 hide: () => {},503 eventWrapper: testContext.eventWrapper,504 };505 jest.spyOn(testContext.list, 'removeEventListener').mockImplementation(() => {});506 jest.spyOn(testContext.dropdown, 'hide').mockImplementation(() => {});507 DropDown.prototype.destroy.call(testContext.dropdown);508 });509 it('it should call .hide', () => {510 expect(testContext.dropdown.hide).toHaveBeenCalled();511 });512 it('it should call .removeEventListener', () => {513 expect(testContext.list.removeEventListener).toHaveBeenCalledWith(514 'click',515 testContext.eventWrapper.clickEvent,516 );517 });518 });...

Full Screen

Full Screen

input_setter_spec.js

Source:input_setter_spec.js Github

copy

Full Screen

1import InputSetter from '~/droplab/plugins/input_setter';2describe('InputSetter', () => {3 let testContext;4 beforeEach(() => {5 testContext = {};6 });7 describe('init', () => {8 beforeEach(() => {9 testContext.config = { InputSetter: {} };10 testContext.hook = { config: testContext.config };11 testContext.inputSetter = {12 addEvents: jest.fn(),13 };14 InputSetter.init.call(testContext.inputSetter, testContext.hook);15 });16 it('should set .hook', () => {17 expect(testContext.inputSetter.hook).toBe(testContext.hook);18 });19 it('should set .config', () => {20 expect(testContext.inputSetter.config).toBe(testContext.config.InputSetter);21 });22 it('should set .eventWrapper', () => {23 expect(testContext.inputSetter.eventWrapper).toEqual({});24 });25 it('should call .addEvents', () => {26 expect(testContext.inputSetter.addEvents).toHaveBeenCalled();27 });28 describe('if config.InputSetter is not set', () => {29 beforeEach(() => {30 testContext.config = { InputSetter: undefined };31 testContext.hook = { config: testContext.config };32 InputSetter.init.call(testContext.inputSetter, testContext.hook);33 });34 it('should set .config to an empty object', () => {35 expect(testContext.inputSetter.config).toEqual({});36 });37 it('should set hook.config to an empty object', () => {38 expect(testContext.hook.config.InputSetter).toEqual({});39 });40 });41 });42 describe('addEvents', () => {43 beforeEach(() => {44 testContext.hook = {45 list: {46 list: {47 addEventListener: jest.fn(),48 },49 },50 };51 testContext.inputSetter = { eventWrapper: {}, hook: testContext.hook, setInputs: () => {} };52 InputSetter.addEvents.call(testContext.inputSetter);53 });54 it('should set .eventWrapper.setInputs', () => {55 expect(testContext.inputSetter.eventWrapper.setInputs).toEqual(expect.any(Function));56 });57 it('should call .addEventListener', () => {58 expect(testContext.hook.list.list.addEventListener).toHaveBeenCalledWith(59 'click.dl',60 testContext.inputSetter.eventWrapper.setInputs,61 );62 });63 });64 describe('removeEvents', () => {65 beforeEach(() => {66 testContext.hook = {67 list: {68 list: {69 removeEventListener: jest.fn(),70 },71 },72 };73 testContext.eventWrapper = {74 setInputs: jest.fn(),75 };76 testContext.inputSetter = { eventWrapper: testContext.eventWrapper, hook: testContext.hook };77 InputSetter.removeEvents.call(testContext.inputSetter);78 });79 it('should call .removeEventListener', () => {80 expect(testContext.hook.list.list.removeEventListener).toHaveBeenCalledWith(81 'click.dl',82 testContext.eventWrapper.setInputs,83 );84 });85 });86 describe('setInputs', () => {87 beforeEach(() => {88 testContext.event = { detail: { selected: {} } };89 testContext.config = [0, 1];90 testContext.inputSetter = { config: testContext.config, setInput: () => {} };91 jest.spyOn(testContext.inputSetter, 'setInput').mockImplementation(() => {});92 InputSetter.setInputs.call(testContext.inputSetter, testContext.event);93 });94 it('should call .setInput for each config element', () => {95 const allArgs = testContext.inputSetter.setInput.mock.calls;96 expect(allArgs.length).toEqual(2);97 allArgs.forEach((args, i) => {98 expect(args[0]).toBe(testContext.config[i]);99 expect(args[1]).toBe(testContext.event.detail.selected);100 });101 });102 describe('if config isnt an array', () => {103 beforeEach(() => {104 testContext.inputSetter = { config: {}, setInput: () => {} };105 InputSetter.setInputs.call(testContext.inputSetter, testContext.event);106 });107 it('should set .config to an array with .config as the first element', () => {108 expect(testContext.inputSetter.config).toEqual([{}]);109 });110 });111 });112 describe('setInput', () => {113 beforeEach(() => {114 testContext.selectedItem = { getAttribute: () => {} };115 testContext.input = { value: 'oldValue', tagName: 'INPUT', hasAttribute: () => {} };116 testContext.config = { valueAttribute: {}, input: testContext.input };117 testContext.inputSetter = { hook: { trigger: {} } };118 testContext.newValue = 'newValue';119 jest.spyOn(testContext.selectedItem, 'getAttribute').mockReturnValue(testContext.newValue);120 jest.spyOn(testContext.input, 'hasAttribute').mockReturnValue(false);121 InputSetter.setInput.call(122 testContext.inputSetter,123 testContext.config,124 testContext.selectedItem,125 );126 });127 it('should call .getAttribute', () => {128 expect(testContext.selectedItem.getAttribute).toHaveBeenCalledWith(129 testContext.config.valueAttribute,130 );131 });132 it('should call .hasAttribute', () => {133 expect(testContext.input.hasAttribute).toHaveBeenCalledWith(undefined);134 });135 it('should set the value of the input', () => {136 expect(testContext.input.value).toBe(testContext.newValue);137 });138 describe('if no config.input is provided', () => {139 beforeEach(() => {140 testContext.config = { valueAttribute: {} };141 testContext.trigger = { value: 'oldValue', tagName: 'INPUT', hasAttribute: () => {} };142 testContext.inputSetter = { hook: { trigger: testContext.trigger } };143 InputSetter.setInput.call(144 testContext.inputSetter,145 testContext.config,146 testContext.selectedItem,147 );148 });149 it('should set the value of the hook.trigger', () => {150 expect(testContext.trigger.value).toBe(testContext.newValue);151 });152 });153 describe('if the input tag is not INPUT', () => {154 beforeEach(() => {155 testContext.input = { textContent: 'oldValue', tagName: 'SPAN', hasAttribute: () => {} };156 testContext.config = { valueAttribute: {}, input: testContext.input };157 InputSetter.setInput.call(158 testContext.inputSetter,159 testContext.config,160 testContext.selectedItem,161 );162 });163 it('should set the textContent of the input', () => {164 expect(testContext.input.textContent).toBe(testContext.newValue);165 });166 });167 describe('if there is an inputAttribute', () => {168 beforeEach(() => {169 testContext.selectedItem = { getAttribute: () => {} };170 testContext.input = { id: 'oldValue', hasAttribute: () => {}, setAttribute: () => {} };171 testContext.inputSetter = { hook: { trigger: {} } };172 testContext.newValue = 'newValue';173 testContext.inputAttribute = 'id';174 testContext.config = {175 valueAttribute: {},176 input: testContext.input,177 inputAttribute: testContext.inputAttribute,178 };179 jest.spyOn(testContext.selectedItem, 'getAttribute').mockReturnValue(testContext.newValue);180 jest.spyOn(testContext.input, 'hasAttribute').mockReturnValue(true);181 jest.spyOn(testContext.input, 'setAttribute').mockImplementation(() => {});182 InputSetter.setInput.call(183 testContext.inputSetter,184 testContext.config,185 testContext.selectedItem,186 );187 });188 it('should call setAttribute', () => {189 expect(testContext.input.setAttribute).toHaveBeenCalledWith(190 testContext.inputAttribute,191 testContext.newValue,192 );193 });194 it('should not set the value or textContent of the input', () => {195 expect(testContext.input.value).not.toBe('newValue');196 expect(testContext.input.textContent).not.toBe('newValue');197 });198 });199 });200 describe('destroy', () => {201 beforeEach(() => {202 testContext.inputSetter = {203 removeEvents: jest.fn(),204 };205 InputSetter.destroy.call(testContext.inputSetter);206 });207 it('should call .removeEvents', () => {208 expect(testContext.inputSetter.removeEvents).toHaveBeenCalled();209 });210 });...

Full Screen

Full Screen

bind_in_out_spec.js

Source:bind_in_out_spec.js Github

copy

Full Screen

1import BindInOut from '~/behaviors/bind_in_out';2import ClassSpecHelper from '../helpers/class_spec_helper';3describe('BindInOut', () => {4 let testContext;5 beforeEach(() => {6 testContext = {};7 });8 describe('constructor', () => {9 beforeEach(() => {10 testContext.in = {};11 testContext.out = {};12 testContext.bindInOut = new BindInOut(testContext.in, testContext.out);13 });14 it('should set .in', () => {15 expect(testContext.bindInOut.in).toBe(testContext.in);16 });17 it('should set .out', () => {18 expect(testContext.bindInOut.out).toBe(testContext.out);19 });20 it('should set .eventWrapper', () => {21 expect(testContext.bindInOut.eventWrapper).toEqual({});22 });23 describe('if .in is an input', () => {24 beforeEach(() => {25 testContext.bindInOut = new BindInOut({ tagName: 'INPUT' });26 });27 it('should set .eventType to keyup ', () => {28 expect(testContext.bindInOut.eventType).toEqual('keyup');29 });30 });31 describe('if .in is a textarea', () => {32 beforeEach(() => {33 testContext.bindInOut = new BindInOut({ tagName: 'TEXTAREA' });34 });35 it('should set .eventType to keyup ', () => {36 expect(testContext.bindInOut.eventType).toEqual('keyup');37 });38 });39 describe('if .in is not an input or textarea', () => {40 beforeEach(() => {41 testContext.bindInOut = new BindInOut({ tagName: 'SELECT' });42 });43 it('should set .eventType to change ', () => {44 expect(testContext.bindInOut.eventType).toEqual('change');45 });46 });47 });48 describe('addEvents', () => {49 beforeEach(() => {50 testContext.in = {51 addEventListener: jest.fn(),52 };53 testContext.bindInOut = new BindInOut(testContext.in);54 testContext.addEvents = testContext.bindInOut.addEvents();55 });56 it('should set .eventWrapper.updateOut', () => {57 expect(testContext.bindInOut.eventWrapper.updateOut).toEqual(expect.any(Function));58 });59 it('should call .addEventListener', () => {60 expect(testContext.in.addEventListener).toHaveBeenCalledWith(61 testContext.bindInOut.eventType,62 testContext.bindInOut.eventWrapper.updateOut,63 );64 });65 it('should return the instance', () => {66 expect(testContext.addEvents).toBe(testContext.bindInOut);67 });68 });69 describe('updateOut', () => {70 beforeEach(() => {71 testContext.in = { value: 'the-value' };72 testContext.out = { textContent: 'not-the-value' };73 testContext.bindInOut = new BindInOut(testContext.in, testContext.out);74 testContext.updateOut = testContext.bindInOut.updateOut();75 });76 it('should set .out.textContent to .in.value', () => {77 expect(testContext.out.textContent).toBe(testContext.in.value);78 });79 it('should return the instance', () => {80 expect(testContext.updateOut).toBe(testContext.bindInOut);81 });82 });83 describe('removeEvents', () => {84 beforeEach(() => {85 testContext.in = {86 removeEventListener: jest.fn(),87 };88 testContext.updateOut = () => {};89 testContext.bindInOut = new BindInOut(testContext.in);90 testContext.bindInOut.eventWrapper.updateOut = testContext.updateOut;91 testContext.removeEvents = testContext.bindInOut.removeEvents();92 });93 it('should call .removeEventListener', () => {94 expect(testContext.in.removeEventListener).toHaveBeenCalledWith(95 testContext.bindInOut.eventType,96 testContext.updateOut,97 );98 });99 it('should return the instance', () => {100 expect(testContext.removeEvents).toBe(testContext.bindInOut);101 });102 });103 describe('initAll', () => {104 beforeEach(() => {105 testContext.ins = [0, 1, 2];106 testContext.instances = [];107 jest.spyOn(document, 'querySelectorAll').mockReturnValue(testContext.ins);108 jest.spyOn(Array.prototype, 'map');109 jest.spyOn(BindInOut, 'init').mockImplementation(() => {});110 testContext.initAll = BindInOut.initAll();111 });112 ClassSpecHelper.itShouldBeAStaticMethod(BindInOut, 'initAll');113 it('should call .querySelectorAll', () => {114 expect(document.querySelectorAll).toHaveBeenCalledWith('*[data-bind-in]');115 });116 it('should call .map', () => {117 expect(Array.prototype.map).toHaveBeenCalledWith(expect.any(Function));118 });119 it('should call .init for each element', () => {120 expect(BindInOut.init.mock.calls.length).toEqual(3);121 });122 it('should return an array of instances', () => {123 expect(testContext.initAll).toEqual(expect.any(Array));124 });125 });126 describe('init', () => {127 beforeEach(() => {128 // eslint-disable-next-line func-names129 jest.spyOn(BindInOut.prototype, 'addEvents').mockImplementation(function() {130 return this;131 });132 // eslint-disable-next-line func-names133 jest.spyOn(BindInOut.prototype, 'updateOut').mockImplementation(function() {134 return this;135 });136 testContext.init = BindInOut.init({}, {});137 });138 ClassSpecHelper.itShouldBeAStaticMethod(BindInOut, 'init');139 it('should call .addEvents', () => {140 expect(BindInOut.prototype.addEvents).toHaveBeenCalled();141 });142 it('should call .updateOut', () => {143 expect(BindInOut.prototype.updateOut).toHaveBeenCalled();144 });145 describe('if no anOut is provided', () => {146 beforeEach(() => {147 testContext.anIn = { dataset: { bindIn: 'the-data-bind-in' } };148 jest.spyOn(document, 'querySelector').mockImplementation(() => {});149 BindInOut.init(testContext.anIn);150 });151 it('should call .querySelector', () => {152 expect(document.querySelector).toHaveBeenCalledWith(153 `*[data-bind-out="${testContext.anIn.dataset.bindIn}"]`,154 );155 });156 });157 });...

Full Screen

Full Screen

sidebar_store_spec.js

Source:sidebar_store_spec.js Github

copy

Full Screen

1import SidebarStore from '~/sidebar/stores/sidebar_store';2import Mock from './mock_data';3import UsersMockHelper from '../helpers/user_mock_data_helper';4const ASSIGNEE = {5 id: 2,6 name: 'gitlab user 2',7 username: 'gitlab2',8 avatar_url: 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',9};10const ANOTHER_ASSINEE = {11 id: 3,12 name: 'gitlab user 3',13 username: 'gitlab3',14 avatar_url: 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',15};16const PARTICIPANT = {17 id: 1,18 state: 'active',19 username: 'marcene',20 name: 'Allie Will',21 web_url: 'foo.com',22 avatar_url: 'gravatar.com/avatar/xxx',23};24const PARTICIPANT_LIST = [PARTICIPANT, { ...PARTICIPANT, id: 2 }, { ...PARTICIPANT, id: 3 }];25describe('Sidebar store', () => {26 let testContext;27 beforeEach(() => {28 testContext = {};29 });30 beforeEach(() => {31 testContext.store = new SidebarStore({32 currentUser: {33 id: 1,34 name: 'Administrator',35 username: 'root',36 avatar_url:37 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',38 },39 editable: true,40 rootPath: '/',41 endpoint: '/gitlab-org/gitlab-shell/issues/5.json',42 });43 });44 afterEach(() => {45 SidebarStore.singleton = null;46 });47 it('has default isFetching values', () => {48 expect(testContext.store.isFetching.assignees).toBe(true);49 });50 it('adds a new assignee', () => {51 testContext.store.addAssignee(ASSIGNEE);52 expect(testContext.store.assignees.length).toEqual(1);53 });54 it('removes an assignee', () => {55 testContext.store.removeAssignee(ASSIGNEE);56 expect(testContext.store.assignees.length).toEqual(0);57 });58 it('finds an existent assignee', () => {59 let foundAssignee;60 testContext.store.addAssignee(ASSIGNEE);61 foundAssignee = testContext.store.findAssignee(ASSIGNEE);62 expect(foundAssignee).toBeDefined();63 expect(foundAssignee).toEqual(ASSIGNEE);64 foundAssignee = testContext.store.findAssignee(ANOTHER_ASSINEE);65 expect(foundAssignee).toBeUndefined();66 });67 it('removes all assignees', () => {68 testContext.store.removeAllAssignees();69 expect(testContext.store.assignees.length).toEqual(0);70 });71 it('sets participants data', () => {72 expect(testContext.store.participants.length).toEqual(0);73 testContext.store.setParticipantsData({74 participants: PARTICIPANT_LIST,75 });76 expect(testContext.store.isFetching.participants).toEqual(false);77 expect(testContext.store.participants.length).toEqual(PARTICIPANT_LIST.length);78 });79 it('sets subcriptions data', () => {80 expect(testContext.store.subscribed).toEqual(null);81 testContext.store.setSubscriptionsData({82 subscribed: true,83 });84 expect(testContext.store.isFetching.subscriptions).toEqual(false);85 expect(testContext.store.subscribed).toEqual(true);86 });87 it('set assigned data', () => {88 const users = {89 assignees: UsersMockHelper.createNumberRandomUsers(3),90 };91 testContext.store.setAssigneeData(users);92 expect(testContext.store.isFetching.assignees).toBe(false);93 expect(testContext.store.assignees.length).toEqual(3);94 });95 it('sets fetching state', () => {96 expect(testContext.store.isFetching.participants).toEqual(true);97 testContext.store.setFetchingState('participants', false);98 expect(testContext.store.isFetching.participants).toEqual(false);99 });100 it('sets loading state', () => {101 testContext.store.setLoadingState('assignees', true);102 expect(testContext.store.isLoading.assignees).toEqual(true);103 });104 it('set time tracking data', () => {105 testContext.store.setTimeTrackingData(Mock.time);106 expect(testContext.store.timeEstimate).toEqual(Mock.time.time_estimate);107 expect(testContext.store.totalTimeSpent).toEqual(Mock.time.total_time_spent);108 expect(testContext.store.humanTimeEstimate).toEqual(Mock.time.human_time_estimate);109 expect(testContext.store.humanTotalTimeSpent).toEqual(Mock.time.human_total_time_spent);110 });111 it('set autocomplete projects', () => {112 const projects = [{ id: 0 }];113 testContext.store.setAutocompleteProjects(projects);114 expect(testContext.store.autocompleteProjects).toEqual(projects);115 });116 it('sets subscribed state', () => {117 expect(testContext.store.subscribed).toEqual(null);118 testContext.store.setSubscribedState(true);119 expect(testContext.store.subscribed).toEqual(true);120 });121 it('set move to project ID', () => {122 const projectId = 7;123 testContext.store.setMoveToProjectId(projectId);124 expect(testContext.store.moveToProjectId).toEqual(projectId);125 });...

Full Screen

Full Screen

project_select_combo_button_spec.js

Source:project_select_combo_button_spec.js Github

copy

Full Screen

1import $ from 'jquery';2import ProjectSelectComboButton from '~/project_select_combo_button';3const fixturePath = 'static/project_select_combo_button.html';4describe('Project Select Combo Button', () => {5 let testContext;6 beforeEach(() => {7 testContext = {};8 });9 preloadFixtures(fixturePath);10 beforeEach(() => {11 testContext.defaults = {12 label: 'Select project to create issue',13 groupId: 12345,14 projectMeta: {15 name: 'My Cool Project',16 url: 'http://mycoolproject.com',17 },18 newProjectMeta: {19 name: 'My Other Cool Project',20 url: 'http://myothercoolproject.com',21 },22 localStorageKey: 'group-12345-new-issue-recent-project',23 relativePath: 'issues/new',24 };25 loadFixtures(fixturePath);26 testContext.newItemBtn = document.querySelector('.new-project-item-link');27 testContext.projectSelectInput = document.querySelector('.project-item-select');28 });29 describe('on page load when localStorage is empty', () => {30 beforeEach(() => {31 testContext.comboButton = new ProjectSelectComboButton(testContext.projectSelectInput);32 });33 it('newItemBtn href is null', () => {34 expect(testContext.newItemBtn.getAttribute('href')).toBe('');35 });36 it('newItemBtn text is the plain default label', () => {37 expect(testContext.newItemBtn.textContent).toBe(testContext.defaults.label);38 });39 });40 describe('on page load when localStorage is filled', () => {41 beforeEach(() => {42 window.localStorage.setItem(43 testContext.defaults.localStorageKey,44 JSON.stringify(testContext.defaults.projectMeta),45 );46 testContext.comboButton = new ProjectSelectComboButton(testContext.projectSelectInput);47 });48 it('newItemBtn href is correctly set', () => {49 expect(testContext.newItemBtn.getAttribute('href')).toBe(50 testContext.defaults.projectMeta.url,51 );52 });53 it('newItemBtn text is the cached label', () => {54 expect(testContext.newItemBtn.textContent).toBe(55 `New issue in ${testContext.defaults.projectMeta.name}`,56 );57 });58 afterEach(() => {59 window.localStorage.clear();60 });61 });62 describe('after selecting a new project', () => {63 beforeEach(() => {64 testContext.comboButton = new ProjectSelectComboButton(testContext.projectSelectInput);65 // mock the effect of selecting an item from the projects dropdown (select2)66 $('.project-item-select')67 .val(JSON.stringify(testContext.defaults.newProjectMeta))68 .trigger('change');69 });70 it('newItemBtn href is correctly set', () => {71 expect(testContext.newItemBtn.getAttribute('href')).toBe(72 'http://myothercoolproject.com/issues/new',73 );74 });75 it('newItemBtn text is the selected project label', () => {76 expect(testContext.newItemBtn.textContent).toBe(77 `New issue in ${testContext.defaults.newProjectMeta.name}`,78 );79 });80 afterEach(() => {81 window.localStorage.clear();82 });83 });84 describe('deriveTextVariants', () => {85 beforeEach(() => {86 testContext.mockExecutionContext = {87 resourceType: '',88 resourceLabel: '',89 };90 testContext.comboButton = new ProjectSelectComboButton(testContext.projectSelectInput);91 testContext.method = testContext.comboButton.deriveTextVariants.bind(92 testContext.mockExecutionContext,93 );94 });95 it('correctly derives test variants for merge requests', () => {96 testContext.mockExecutionContext.resourceType = 'merge_requests';97 testContext.mockExecutionContext.resourceLabel = 'New merge request';98 const returnedVariants = testContext.method();99 expect(returnedVariants.localStorageItemType).toBe('new-merge-request');100 expect(returnedVariants.defaultTextPrefix).toBe('New merge request');101 expect(returnedVariants.presetTextSuffix).toBe('merge request');102 });103 it('correctly derives text variants for issues', () => {104 testContext.mockExecutionContext.resourceType = 'issues';105 testContext.mockExecutionContext.resourceLabel = 'New issue';106 const returnedVariants = testContext.method();107 expect(returnedVariants.localStorageItemType).toBe('new-issue');108 expect(returnedVariants.defaultTextPrefix).toBe('New issue');109 expect(returnedVariants.presetTextSuffix).toBe('issue');110 });111 });...

Full Screen

Full Screen

hook_spec.js

Source:hook_spec.js Github

copy

Full Screen

1import Hook from '~/droplab/hook';2import DropDown from '~/droplab/drop_down';3jest.mock('~/droplab/drop_down', () => jest.fn());4describe('Hook', () => {5 let testContext;6 beforeEach(() => {7 testContext = {};8 });9 describe('class constructor', () => {10 beforeEach(() => {11 testContext.trigger = { id: 'id' };12 testContext.list = {};13 testContext.plugins = {};14 testContext.config = {};15 testContext.hook = new Hook(16 testContext.trigger,17 testContext.list,18 testContext.plugins,19 testContext.config,20 );21 });22 it('should set .trigger', () => {23 expect(testContext.hook.trigger).toBe(testContext.trigger);24 });25 it('should set .list', () => {26 expect(testContext.hook.list).toEqual({});27 });28 it('should call DropDown constructor', () => {29 expect(DropDown).toHaveBeenCalledWith(testContext.list, testContext.config);30 });31 it('should set .type', () => {32 expect(testContext.hook.type).toBe('Hook');33 });34 it('should set .event', () => {35 expect(testContext.hook.event).toBe('click');36 });37 it('should set .plugins', () => {38 expect(testContext.hook.plugins).toBe(testContext.plugins);39 });40 it('should set .config', () => {41 expect(testContext.hook.config).toBe(testContext.config);42 });43 it('should set .id', () => {44 expect(testContext.hook.id).toBe(testContext.trigger.id);45 });46 describe('if config argument is undefined', () => {47 beforeEach(() => {48 testContext.config = undefined;49 testContext.hook = new Hook(50 testContext.trigger,51 testContext.list,52 testContext.plugins,53 testContext.config,54 );55 });56 it('should set .config to an empty object', () => {57 expect(testContext.hook.config).toEqual({});58 });59 });60 describe('if plugins argument is undefined', () => {61 beforeEach(() => {62 testContext.plugins = undefined;63 testContext.hook = new Hook(64 testContext.trigger,65 testContext.list,66 testContext.plugins,67 testContext.config,68 );69 });70 it('should set .plugins to an empty array', () => {71 expect(testContext.hook.plugins).toEqual([]);72 });73 });74 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 })6})7describe('My First Test Suite', function() {8 it('Does not do much!', function() {9 cy.contains('type').click()10 cy.url().should('include', '/commands/actions')11 })12 it('Does not do much!', function() {13 cy.contains('type').click()14 cy.url().should('include', '/commands/actions')15 })16})17it('Does not do much!', function() {18 cy.contains('type').click()19 cy.url().should('include', '/commands/actions')20})21cy.contains('type').click()22cy.url().should('include', '/commands/actions')23cy.contains('type').click()24cy.url().should('include', '/commands/actions')25cy.get('.action-email')26 .should('have.value', '

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("My First Test", function() {2 it("Does not do much!", function() {3 cy.contains("type").click();4 cy.url().should("include", "/commands/actions");5 cy.get(".action-email")6 .type("

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 expect(true).to.equal(false)4 })5})6describe('My Second Test', function() {7 it('Does not do much!', function() {8 expect(true).to.equal(false)9 })10})11describe('My Third Test', function() {12 it('Does not do much!', function() {13 expect(true).to.equal(false)14 })15})16describe('My First Test', function() {17 it('Does not do much!', function() {18 expect(true).to.equal(false)19 })20})21describe('My Second Test', function() {22 it('Does not do much!', function() {23 expect(true).to.equal(false)24 })25})26describe('My Third Test', function() {27 it('Does not do much!', function() {28 expect(true).to.equal(false)29 })30})31describe('My First Test', function() {32 it('Does not do much!', function() {33 expect(true).to.equal(false)34 })35})36describe('My Second Test', function() {37 it('Does not do much!', function() {38 expect(true).to.equal(false)39 })40})41describe('My Third Test', function() {42 it('Does not do much!', function() {43 expect(true).to.equal(false)44 })45})46describe('My First Test', function() {47 it('Does not do much!', function() {48 expect(true).to.equal(false)49 })50})51describe('My Second Test', function() {52 it('Does not do much!', function() {53 expect(true).to.equal(false)54 })55})56describe('My Third Test', function() {57 it('Does not do

Full Screen

Using AI Code Generation

copy

Full Screen

1context('My First Test', () => {2 it('Does not do much!', () => {3 expect(true).to.equal(true)4 })5})6describe('My First Test', () => {7 it('Does not do much!', () => {8 expect(true).to.equal(true)9 })10})11it('Does not do much!', () => {12 expect(true).to.equal(true)13})14it('Does not do much!', () => {15 expect(true).to.equal(true)16})17it('Does not do much!', () => {18 expect(true).to.equal(true)19})20it('Does not do much!', () => {21 expect(true).to.equal(true)22})23it('Does not do much!', () => {24 expect(true).to.equal(true)25})26it('Does not do much!', () => {27 expect(true).to.equal(true)28})29it('Does not do much!', () => {30 expect(true).to.equal(true)31})32it('Does not do much!', () => {33 expect(true).to.equal(true)34})35it('Does not do much!', () => {36 expect(true).to.equal(true)37})

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('testContext', () => {2 it('test', () => {3 cy.testContext();4 });5});6module.exports = (on, config) => {7 on('task', {8 testContext() {9 console.log('testContext', Cypress.config());10 return null;11 }12 });13};14{

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', function () {2 it('test', function () {3 cy.testContext();4 });5});6Cypress.Commands.add('testContext', function () {7 console.log(this);8});9describe('test', function () {10 it('test', function () {11 cy.testContext();12 });13});14Cypress.Commands.add('testContext', function () {15 console.log(this);16});17Cypress.Commands.add('testContext', function () {18 console.log(this);19});20Cypress.Commands.add('testContext', function () {21 console.log(this);22});23Cypress.Commands.add('testContext', function () {24 console.log(this);25});26Cypress.Commands.add('testContext', function () {27 console.log(this);28});

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful