How to use fake.yields method in sinon

Best JavaScript code snippet using sinon

modelHandlersSpec.js

Source:modelHandlersSpec.js Github

copy

Full Screen

...61 modelsWithTask: [modelsResult[0]],62 modelsWithoutTask: []63 };64 modelServiceStub.partitionModels = sinon.fake.returns(partitionResult);65 modelRepositoryStub.findByAnalysis = sinon.fake.yields(null, modelsResult);66 pataviTaskRepositoryStub.getPataviTasksStatus = sinon.fake.yields(null, pataviResult);67 modelHandlers.find(request, response, next);68 expect(response.json).to.have.been.called.with(expectedModelArray);69 });70 it('should call response.json with models without tasks', function() {71 var response = {72 json: chai.spy()73 };74 var next = chai.spy();75 var expectedModelArray = [{}];76 var modelsResult = [{}];77 var partitionResult = {78 modelsWithTask: [],79 modelsWithoutTask: [modelsResult[0]]80 };81 modelServiceStub.partitionModels = sinon.fake.returns(partitionResult);82 modelRepositoryStub.findByAnalysis = sinon.fake.yields(null, modelsResult);83 modelHandlers.find(request, response, next);84 expect(response.json).to.have.been.called.with(expectedModelArray);85 });86 it('should call next with an error object when an error occurs while retrieving models from the repository', function() {87 var response = {};88 var next = chai.spy();89 modelRepositoryStub.findByAnalysis = sinon.fake.yields(errorMessage);90 modelHandlers.find(request, response, next);91 expect(next).to.have.been.called.with(error500);92 });93 it('should call next with an error object when an error occurs while gettig the status of Patavi tasks', function() {94 var response = {};95 var next = chai.spy();96 var modelsResult = [97 { taskUrl: 'taskUrl' }98 ];99 var partitionResult = {100 modelsWithTask: [modelsResult[0]],101 modelsWithoutTask: []102 };103 modelServiceStub.partitionModels = sinon.fake.returns(partitionResult);104 modelRepositoryStub.findByAnalysis = sinon.fake.yields(null, modelsResult);105 pataviTaskRepositoryStub.getPataviTasksStatus = sinon.fake.yields(errorMessage);106 modelHandlers.find(request, response, next);107 expect(next).to.have.been.called.with(error500);108 });109 });110 describe('getResult', function() {111 var request = {112 params: {113 analysisId: analysisId,114 modelId: modelId115 }116 };117 var response;118 it('should pass an error to next when attempting to get a model from the repository', function(done) {119 var next = function(thrownError) {120 expect(thrownError).to.deep.equal(error500);121 done();122 };123 modelRepositoryStub.get = sinon.fake.yields(errorMessage);124 modelHandlers.getResult(request, response, next);125 });126 it('should pass an error to next when attempting to get results of model with no task', function(done) {127 var noTaskError = {128 message: 'Error, model ' + modelId + ' does not have a task url',129 statusCode: 500130 };131 var next = function(thrownError) {132 expect(thrownError).to.deep.equal(noTaskError);133 done();134 };135 var modelResult = {};136 modelRepositoryStub.get = sinon.fake.yields(null, modelResult);137 modelHandlers.getResult(request, response, next);138 });139 it('should pass an error to next when attempting to get patavi result', function(done) {140 var taskUrl = 'url';141 var next = function(thrownError) {142 expect(thrownError).to.deep.equal(error500);143 done();144 };145 var modelResult = {146 taskUrl: taskUrl147 };148 modelRepositoryStub.get = sinon.fake.yields(null, modelResult);149 pataviTaskRepositoryStub.getResult = sinon.fake.yields(errorMessage);150 modelHandlers.getResult(request, response, next);151 });152 it('should call response.status with 200 and response.json with the patavi result', function(done) {153 var pataviResult = {};154 var next = chai.spy();155 var expectations = function(result) {156 expect(response.status).to.have.been.called.with(200);157 expect(result).to.deep.equal(pataviResult);158 expect(next).to.not.have.been.called();159 done();160 };161 var response = {162 status: chai.spy(),163 json: expectations164 };165 var taskUrl = 'url';166 var modelResult = {167 taskUrl: taskUrl168 };169 modelRepositoryStub.get = sinon.fake.yields(null, modelResult);170 pataviTaskRepositoryStub.getResult = sinon.fake.yields(null, pataviResult);171 modelHandlers.getResult(request, response, next);172 });173 });174 describe('createModel', function() {175 var request = {176 params: {177 analysisId: analysisId178 },179 body: {}180 };181 it('should call the repository to create a new model', function(done) {182 var next = chai.spy();183 var expectations = function(returnId) {184 expect(returnId).to.deep.equal({185 id: modelId186 });187 expect(response.location).to.have.been.called.with('/analyses/' + analysisId + '/models/' + modelId);188 expect(response.status).to.have.been.called.with(201);189 expect(next).to.have.not.been.called();190 done();191 };192 var response = {193 location: chai.spy(),194 status: chai.spy(),195 json: expectations196 };197 modelRepositoryStub.create = sinon.fake.yields(null, modelId);198 modelHandlers.createModel(request, response, next);199 });200 it('should call next with an error if the model can\'t be created', function(done) {201 var next = function(thrownError) {202 expect(thrownError).to.deep.equal(error500);203 done();204 };205 var response = {};206 modelRepositoryStub.create = sinon.fake.yields(errorMessage);207 modelHandlers.createModel(request, response, next);208 });209 });210 describe('extendRunLength', function() {211 var request = {212 params: {213 analysisId: analysisId,214 modelId: modelId215 },216 body: {}217 };218 var model = {219 analysisId: analysisId,220 taskUrl: 'url'221 };222 it('should update an existing model to have more iterations and call response.sendStatus when successful', function(done) {223 var next = chai.spy();224 var expectations = function(status) {225 expect(status).to.equal(200);226 expect(next).to.have.not.been.called();227 done();228 };229 var response = {230 sendStatus: expectations231 };232 modelRepositoryStub.get = sinon.fake.yields(null, model);233 modelServiceStub.update = sinon.fake.yields(null);234 pataviTaskRepositoryStub.deleteTask = sinon.fake.yields(null);235 modelHandlers.extendRunLength(request, response, next);236 });237 it('should call next with an error if the model cannot be retrieved', function(done) {238 var next = function(thrownError) {239 expect(thrownError).to.deep.equal(error500);240 done();241 };242 var response = {};243 modelRepositoryStub.get = sinon.fake.yields(errorMessage);244 modelHandlers.extendRunLength(request, response, next);245 });246 it('should call next with an error if the model cannot be updated', function(done) {247 var next = function(thrownError) {248 expect(thrownError).to.deep.equal(error500);249 done();250 };251 var response = {};252 modelRepositoryStub.get = sinon.fake.yields(null, model);253 modelServiceStub.update = sinon.fake.yields(errorMessage);254 modelHandlers.extendRunLength(request, response, next);255 });256 it('should call next with an error if the task cannot be deleted', function(done) {257 var next = function(thrownError) {258 expect(thrownError).to.deep.equal(error500);259 done();260 };261 var response = {};262 modelRepositoryStub.get = sinon.fake.yields(null, model);263 modelServiceStub.update = sinon.fake.yields(null);264 pataviTaskRepositoryStub.deleteTask = sinon.fake.yields(errorMessage);265 modelHandlers.extendRunLength(request, response, next);266 });267 it('should call next with an error if the coordinates do not match', function(done) {268 var next = function(thrownError) {269 expect(thrownError).to.deep.equal(coordinateError);270 done();271 };272 var modelWithWrongAnalysis = {273 analysisId: 1337,274 taskUrl: 'url'275 };276 var response = {};277 modelRepositoryStub.get = sinon.fake.yields(null, modelWithWrongAnalysis);278 modelHandlers.extendRunLength(request, response, next);279 });280 });281 describe('addFunnelPlot', function() {282 var request = {283 params: {284 analysisId: analysisId,285 modelId: modelId286 },287 body: {}288 };289 var model = {290 analysisId: analysisId,291 taskUrl: 'url'292 };293 it('should add a funnel plot and call response.sendStatus when successful', function(done) {294 var next = chai.spy();295 var expectations = function(status) {296 expect(status).to.equal(201);297 expect(next).to.have.not.been.called();298 done();299 };300 var response = {301 sendStatus: expectations302 };303 modelRepositoryStub.get = sinon.fake.yields(null, model);304 funnelPlotRepositoryStub.create = sinon.fake.yields(null);305 modelHandlers.addFunnelPlot(request, response, next);306 });307 it('should call next with an error if the model cannot be retrieved', function(done) {308 var next = function(thrownError) {309 expect(thrownError).to.deep.equal(error500);310 done();311 };312 var response = {};313 modelRepositoryStub.get = sinon.fake.yields(errorMessage);314 modelHandlers.addFunnelPlot(request, response, next);315 });316 it('should call next with an error if the funnel plot can not be created', function(done) {317 var next = function(thrownError) {318 expect(thrownError).to.deep.equal(error500);319 done();320 };321 var response = {};322 modelRepositoryStub.get = sinon.fake.yields(null, model);323 funnelPlotRepositoryStub.create = sinon.fake.yields(errorMessage);324 modelHandlers.addFunnelPlot(request, response, next);325 });326 it('should call next with an error if the coordinates do not match', function(done) {327 var next = function(thrownError) {328 expect(thrownError).to.deep.equal(coordinateError);329 done();330 };331 var modelWithWrongAnalysis = {332 analysisId: 1337,333 taskUrl: 'url'334 };335 var response = {};336 modelRepositoryStub.get = sinon.fake.yields(null, modelWithWrongAnalysis);337 modelHandlers.addFunnelPlot(request, response, next);338 });339 });340 describe('queryFunnelPlots', function() {341 var request = {342 params: {343 modelId: modelId344 }345 };346 it('should query a funnel plot given a model id and call response.json with the result', function() {347 var response = {348 json: chai.spy()349 };350 var next = chai.spy();351 var result = {};352 funnelPlotRepositoryStub.findByModelId = sinon.fake.yields(null, result);353 modelHandlers.queryFunnelPlots(request, response, next);354 expect(response.json).to.have.been.called.with(result);355 });356 it('should call next with an error', function() {357 var response = {};358 var next = chai.spy();359 funnelPlotRepositoryStub.findByModelId = sinon.fake.yields(errorMessage);360 modelHandlers.queryFunnelPlots(request, response, next);361 expect(next).to.have.been.called.with(error500);362 });363 });364 describe('getFunnelPlot', function() {365 var request = {366 params: {367 plotId: -2368 }369 };370 it('should query a funnel plot given a model id and call response.json with the result', function() {371 var response = {372 json: chai.spy()373 };374 var next = chai.spy();375 var result = {};376 funnelPlotRepositoryStub.findByPlotId = sinon.fake.yields(null, result);377 modelHandlers.getFunnelPlot(request, response, next);378 expect(response.json).to.have.been.called.with(result);379 });380 it('should call next with an error', function() {381 var response = {};382 var next = chai.spy();383 funnelPlotRepositoryStub.findByPlotId = sinon.fake.yields(errorMessage);384 modelHandlers.getFunnelPlot(request, response, next);385 expect(next).to.have.been.called.with(error500);386 });387 });388 describe('setAttributes', function() {389 var request = {390 params: {391 analysisId: analysisId,392 modelId: modelId393 },394 body: {395 isArchived: false396 }397 };398 var model = {399 id: modelId,400 analysisId: analysisId401 };402 it('should set the model attributes and call response.sendStatus when successful', function(done) {403 var next = chai.spy();404 var expectations = function(status) {405 expect(status).to.equal(200);406 expect(next).to.not.have.been.called();407 done();408 };409 var response = {410 sendStatus: expectations411 };412 modelRepositoryStub.get = sinon.fake.yields(null, model);413 modelRepositoryStub.setArchive = sinon.fake.yields(null);414 modelHandlers.setAttributes(request, response, next);415 });416 it('should call next with an error if the model could not be retrieved', function(done) {417 var response;418 var next = function(thrownError) {419 expect(thrownError).to.deep.equal(error500);420 done();421 };422 modelRepositoryStub.get = sinon.fake.yields(errorMessage);423 modelHandlers.setAttributes(request, response, next);424 });425 it('should call next with an error if the archived status could not be set', function(done) {426 var response;427 var next = function(thrownError) {428 expect(thrownError).to.deep.equal(error500);429 done();430 };431 modelRepositoryStub.get = sinon.fake.yields(null, model);432 modelRepositoryStub.setArchive = sinon.fake.yields(errorMessage);433 modelHandlers.setAttributes(request, response, next);434 });435 it('should call next with an error if the coordinates do not match', function(done) {436 var response;437 var next = function(thrownError) {438 expect(thrownError).to.deep.equal(coordinateError);439 done();440 };441 var modelWithWrongAnalysis = {442 analysisId: 1337,443 modelId: modelId444 };445 modelRepositoryStub.get = sinon.fake.yields(null, modelWithWrongAnalysis);446 modelRepositoryStub.setArchive = sinon.fake.yields(errorMessage);447 modelHandlers.setAttributes(request, response, next);448 });449 });450 describe('getModel', function() {451 var request = {452 params: {453 modelId: 1454 }455 };456 it('should query the model repository and call response.json with the result', function() {457 var response = {458 json: chai.spy()459 };460 var next = chai.spy();461 var result = {};462 modelRepositoryStub.get = sinon.fake.yields(null, result);463 modelHandlers.getModel(request, response, next);464 expect(response.json).to.have.been.called.with(result);465 expect(next).to.not.have.been.called();466 });467 it('should, if an error occurs, pass it to next', function() {468 var response = {};469 var next = chai.spy();470 modelRepositoryStub.get = sinon.fake.yields(errorMessage);471 modelHandlers.getModel(request, response, next);472 expect(next).to.have.been.called.with(error404);473 });474 });475 describe('getBaseline', function() {476 var request = {477 params: {478 modelId: 1479 }480 };481 it('should query the modelBaseline repository', function() {482 var response = {483 json: chai.spy()484 };485 var next = chai.spy();486 var result = { rows: [] };487 modelBaselineRepositoryStub.get = sinon.fake.yields(null, result);488 modelHandlers.getBaseline(request, response, next);489 expect(response.json).to.have.been.called.with(result);490 expect(next).to.not.have.been.called();491 });492 it('should, if an error occurs, pass it to next', function() {493 var response = {};494 var next = chai.spy();495 modelBaselineRepositoryStub.get = sinon.fake.yields(errorMessage);496 modelHandlers.getBaseline(request, response, next);497 expect(next).to.have.been.called.with(error500);498 });499 });500 describe('setBaseline', function() {501 var modelId = 1;502 var request = {503 params: {504 analysisId: -1,505 modelId: modelId506 },507 body: {}508 };509 it('should query the modelBaseline repository', function(done) {510 var response = {511 sendStatus: function(result) {512 expect(result).to.equal(200);513 done();514 }515 };516 var next = chai.spy();517 var model = {518 analysisId: -1519 };520 modelRepositoryStub.get = sinon.fake.yields(null, model);521 modelBaselineRepositoryStub.set = sinon.fake.yields(null);522 modelHandlers.setBaseline(request, response, next);523 expect(next).to.not.have.been.called();524 });525 it('should call next with an error if the coordinates do not match', function(done) {526 var response = {};527 var next = function(thrownError) {528 expect(thrownError).to.deep.equal(coordinateError);529 done();530 };531 modelRepositoryStub.get = sinon.fake.yields(null, 'someModel');532 modelBaselineRepositoryStub.get = sinon.fake.yields(errorMessage);533 modelHandlers.setBaseline(request, response, next);534 });535 it('should, if the model cant be gotten pass an error to next', function(done) {536 var response = {};537 var message = 'Error setting baseline for model: ' + modelId;538 var error = {539 statusCode: 500,540 message: message541 };542 var next = function(thrownError) {543 expect(thrownError).to.deep.equal(error);544 done();545 };546 modelRepositoryStub.get = sinon.fake.yields(message);547 modelHandlers.setBaseline(request, response, next);548 });549 });550 describe('setTitle', function() {551 var request = {552 params: {553 modelId: 1554 },555 body: {556 newTitle: 'newTitle'557 }558 };559 it('should call the repository.setTitle', function() {560 var response = {561 sendStatus: chai.spy()562 };563 var next = chai.spy();564 modelRepositoryStub.setTitle = sinon.fake.yields(null);565 modelHandlers.setTitle(request, response, next);566 expect(response.sendStatus).to.have.been.called.with(200);567 });568 it('should call next with an error if one occurs', function() {569 var response = {};570 var next = chai.spy();571 modelRepositoryStub.setTitle = sinon.fake.yields(errorMessage);572 modelHandlers.setTitle(request, response, next);573 expect(next).to.have.been.called.with(error500);574 });575 });576 describe('deleteModel', function(){577 var request = {578 params: {579 modelId: 1580 }581 };582 it('should call the repository.deleteModel', function() {583 var response = {584 sendStatus: chai.spy()585 };586 var next = chai.spy();587 modelRepositoryStub.deleteModel = sinon.fake.yields(null);588 modelHandlers.deleteModel(request, response, next);589 expect(response.sendStatus).to.have.been.called.with(200);590 });591 it('should call next with an error if one occurs', function() {592 var response = {};593 var next = chai.spy();594 modelRepositoryStub.deleteModel = sinon.fake.yields(errorMessage);595 modelHandlers.deleteModel(request, response, next);596 expect(next).to.have.been.called.with(error500);597 });598 });...

Full Screen

Full Screen

analysisHandlersSpec.js

Source:analysisHandlersSpec.js Github

copy

Full Screen

...34 json: chai.spy()35 };36 var next = chai.spy();37 var result = { rows: [] };38 analysisRepositoryStub.query = sinon.fake.yields(undefined, result);39 analysisHandlers.queryAnalyses(request, response, next);40 expect(response.json).to.have.been.called.with(result.rows);41 expect(next).to.not.have.been.called();42 });43 it('should if an error occurs pass it to next', function() {44 var response = {};45 var next = chai.spy();46 analysisRepositoryStub.query = sinon.fake.yields('error');47 analysisHandlers.queryAnalyses(request, response, next);48 expectError(next);49 });50 });51 describe('getAnalysis', function() {52 var request = {53 params: {54 analysisId: 155 }56 };57 it('should get analysis given an id', function() {58 var response = {59 json: chai.spy()60 };61 var next = chai.spy();62 var analysis = {};63 analysisRepositoryStub.get = sinon.fake.yields(undefined, analysis);64 analysisHandlers.getAnalysis(request, response, next);65 expect(response.json).to.have.been.called.with(analysis);66 expect(next).to.not.have.been.called();67 });68 it('should if an error occurs pass it to next', function() {69 var response = {};70 var next = chai.spy();71 analysisRepositoryStub.get = sinon.fake.yields('error');72 analysisHandlers.getAnalysis(request, response, next);73 expectError(next);74 });75 });76 describe('createAnalysis', function() {77 var request = {78 user: {79 id: 180 },81 body: 'body'82 };83 it('should create analysis', function() {84 var response = {85 location: chai.spy(),86 sendStatus: chai.spy()87 };88 var next = chai.spy();89 var newAnalysisId = 1;90 analysisRepositoryStub.create = sinon.fake.yields(undefined, newAnalysisId);91 analysisHandlers.createAnalysis(request, response, next);92 expect(response.location).to.have.been.called.with('/analyses/' + newAnalysisId);93 expect(response.sendStatus).to.have.been.called.with(201);94 expect(next).to.not.have.been.called();95 });96 it('should if an error occurs pass it to next', function() {97 var response = {};98 var next = chai.spy();99 analysisRepositoryStub.create = sinon.fake.yields('error');100 analysisHandlers.createAnalysis(request, response, next);101 expectError(next);102 });103 });104 describe('setPrimaryModel', function() {105 var request = {106 params: {107 analysisId: 1108 },109 query: {110 modelId: 1111 }112 };113 it('should set the primary model', function() {114 var response = {115 location: chai.spy(),116 sendStatus: chai.spy()117 };118 var next = chai.spy();119 analysisRepositoryStub.setPrimaryModel = sinon.fake.yields(undefined);120 analysisHandlers.setPrimaryModel(request, response, next);121 expect(response.sendStatus).to.have.been.called.with(200);122 expect(next).to.not.have.been.called();123 });124 it('should if an error occurs pass it to next', function() {125 var response = {};126 var next = chai.spy();127 analysisRepositoryStub.setPrimaryModel = sinon.fake.yields('error');128 analysisHandlers.setPrimaryModel(request, response, next);129 expectError(next);130 });131 });132 describe('getProblem', function() {133 var request = {134 params: {135 analysisId: 1136 }137 };138 it('should get the problem', function() {139 var response = {140 json: chai.spy()141 };142 var result = {143 problem: ''144 };145 var next = chai.spy();146 analysisRepositoryStub.get = sinon.fake.yields(undefined, result);147 analysisHandlers.getProblem(request, response, next);148 expect(response.json).to.have.been.called.with(result.problem);149 expect(next).to.not.have.been.called();150 });151 it('should if an error occurs pass it to next', function() {152 var response = {};153 var next = chai.spy();154 analysisRepositoryStub.get = sinon.fake.yields('error');155 analysisHandlers.getProblem(request, response, next);156 expectError(next);157 });158 });159 describe('setTitle', function() {160 var request = {161 params: {162 analysisId: 1163 },164 body: {165 newTitle: 'newTitle'166 }167 };168 it('should update the analysis title', function() {169 var response = {170 sendStatus: chai.spy()171 };172 var next = chai.spy();173 analysisRepositoryStub.setTitle = sinon.fake.yields();174 analysisHandlers.setTitle(request, response, next);175 expect(response.sendStatus).to.have.been.called.with(200);176 expect(next).to.not.have.been.called();177 });178 it('should if an error occurs pass it to next', () => {179 var response = {};180 var next = chai.spy();181 analysisRepositoryStub.setTitle = sinon.fake.yields('error');182 analysisHandlers.setTitle(request, response, next);183 expectError(next);184 });185 });186 describe('setOutcome', function() {187 var request = {188 params: {189 analysisId: 1190 },191 body: {192 name: 'newName',193 direction: -1194 }195 };196 it('should update the outcome of the analysis', function() {197 var response = {198 sendStatus: chai.spy()199 };200 var next = chai.spy();201 analysisRepositoryStub.setOutcome = sinon.fake.yields();202 analysisHandlers.setOutcome(request, response, next);203 expect(response.sendStatus).to.have.been.called.with(200);204 expect(next).to.not.have.been.called();205 });206 it('should if an error occurs pass it to next', () => {207 var response = {};208 var next = chai.spy();209 analysisRepositoryStub.setOutcome = sinon.fake.yields('error');210 analysisHandlers.setOutcome(request, response, next);211 expectError(next);212 });213 });214 describe('deleteAnalysis', function() {215 var request = {216 params: {217 analysisId: 1218 }219 };220 it('should call the repository function responsible for deletion', () => {221 var response = {222 sendStatus: chai.spy()223 };224 var next = chai.spy();225 analysisRepositoryStub.deleteAnalysis = sinon.fake.yields();226 analysisHandlers.deleteAnalysis(request, response, next);227 expect(response.sendStatus).to.have.been.called.with(200);228 expect(next).to.not.have.been.called();229 });230 it('should if an error occurs pass it to next', () => {231 var response = {};232 var next = chai.spy();233 analysisRepositoryStub.deleteAnalysis = sinon.fake.yields('error');234 analysisHandlers.deleteAnalysis(request, response, next);235 expectError(next);236 });237 });238 describe('setProblem', function() {239 var request = {240 params: {241 analysisId: 1242 },243 body: {}244 };245 var errorMessage = 'error';246 var error = {247 message: errorMessage,248 statusCode: 500249 };250 var modelsWithTasks = {251 modelsWithTask: [{252 taskUrl: 'taskUrl',253 id: 37254 }]255 };256 var models = [];257 var response = {};258 it('should call the repository function responsible for updating the analysis problem', (done) => {259 var response = {260 sendStatus: function(code) {261 expect(code).to.equal(200);262 expect(next).to.not.have.been.called();263 done();264 }265 };266 var next = chai.spy();267 modelRepositoryStub.findByAnalysis = sinon.fake.yields(null, models);268 modelServiceStub.partitionModels = sinon.fake.returns(modelsWithTasks);269 pataviTaskRepositoryStub.deleteTask = sinon.fake.yields(null);270 modelRepositoryStub.setTaskUrl = sinon.fake.yields(null);271 analysisRepositoryStub.setProblem = sinon.fake.yields(null);272 analysisHandlers.setProblem(request, response, next);273 });274 it('should call next with an error if modelRepository.findByAnalysis fails', (done) => {275 var next = function(thrownError) {276 expect(thrownError).to.deep.equal(error);277 done();278 };279 modelRepositoryStub.findByAnalysis = sinon.fake.yields(errorMessage);280 analysisHandlers.setProblem(request, response, next);281 });282 it('should call next with an error if pataviTaskRepositoryStub.deleteTask fails', (done) => {283 var next = function(thrownError) {284 expect(thrownError).to.deep.equal(error);285 done();286 };287 modelRepositoryStub.findByAnalysis = sinon.fake.yields(null, models);288 modelServiceStub.partitionModels = sinon.fake.returns(modelsWithTasks);289 pataviTaskRepositoryStub.deleteTask = sinon.fake.yields(errorMessage);290 analysisHandlers.setProblem(request, response, next);291 });292 it('should call next with an error if modelRepositoryStub.setTaskUrl fails', (done) => {293 var next = function(thrownError) {294 expect(thrownError).to.deep.equal(error);295 done();296 };297 modelRepositoryStub.findByAnalysis = sinon.fake.yields(null, models);298 modelServiceStub.partitionModels = sinon.fake.returns(modelsWithTasks);299 pataviTaskRepositoryStub.deleteTask = sinon.fake.yields(null);300 modelRepositoryStub.setTaskUrl = sinon.fake.yields(errorMessage);301 analysisHandlers.setProblem(request, response, next);302 });303 it('should call next with an error if analysisRepositoryStub.setProblem fails', (done) => {304 var next = function(thrownError) {305 expect(thrownError).to.deep.equal(error);306 done();307 };308 modelRepositoryStub.findByAnalysis = sinon.fake.yields(null, models);309 modelServiceStub.partitionModels = sinon.fake.returns(modelsWithTasks);310 pataviTaskRepositoryStub.deleteTask = sinon.fake.yields(null);311 modelRepositoryStub.setTaskUrl = sinon.fake.yields(null);312 analysisRepositoryStub.setProblem = sinon.fake.yields(errorMessage);313 analysisHandlers.setProblem(request, response, next);314 });315 });...

Full Screen

Full Screen

controllerProjects.spec.js

Source:controllerProjects.spec.js Github

copy

Full Screen

...16 status: () => { },17 json: () => { },18 send: () => { }19 }20 const createFake = sinon.fake.yields('error', null);21 sinon.replace(Project, 'create', createFake);22 const spySend = sinon.spy(res, 'send');23 controller(Project).post(req, res);24 expect(spySend.calledWith(404)).to.be.true;25 });26 it('should create new project and NOT send an error, POST', () => {27 const Project = {28 create: () => { }29 }30 const req = {31 body: {}32 }33 const res = {34 status: () => { },35 json: () => { },36 send: () => { }37 }38 const createFake = sinon.fake.yields('', 'project');39 sinon.replace(Project, 'create', createFake);40 const spyJson = sinon.spy(res, 'json');41 controller(Project).post(req, res);42 expect(spyJson.calledWith('error')).to.be.false;43 });44 it('should get project and send an error, GET', () => {45 const Project = {46 find: () => { }47 }48 const req = {49 query: {}50 }51 const res = {52 status: () => { },53 json: () => { },54 send: () => { }55 }56 const findFake = sinon.fake.yields('error', null);57 sinon.replace(Project, 'find', findFake);58 const spySend = sinon.spy(res, 'send');59 controller(Project).get(req, res);60 expect(spySend.calledWith('error')).to.be.true;61 });62 it('should get project and send an error, GET', () => {63 const Project = {64 find: () => { }65 }66 const req = {67 query: {}68 }69 const res = {70 status: () => { },71 json: () => { },72 send: () => { }73 }74 const findFake = sinon.fake.yields('', 'project');75 sinon.replace(Project, 'find', findFake);76 const spySend = sinon.spy(res, 'send');77 controller(Project).get(req, res);78 expect(spySend.calledWith('error')).to.be.false;79 });80 it('should find project and send an error, DELETER', () => {81 const Project = {82 find: () => { },83 deleteOne: () => { }84 }85 const req = {86 query: {}87 }88 const res = {89 status: () => { },90 json: () => { },91 send: () => { }92 }93 const findFake = sinon.fake.yields('error', null);94 sinon.replace(Project, 'find', findFake);95 const spySend = sinon.spy(res, 'send');96 controller(Project).deleter(req, res);97 expect(spySend.calledWith('error')).to.be.true;98 });99 it('should find project and NOT send an error, DELETER', () => {100 const Project = {101 find: () => { },102 deleteOne: () => { }103 }104 const req = {105 query: {}106 }107 const res = {108 status: () => { },109 json: () => { },110 send: () => { }111 }112 const findFake = sinon.fake.yields('', 'project');113 sinon.replace(Project, 'find', findFake);114 const spySend = sinon.spy(res, 'send');115 controller(Project).deleter(req, res);116 expect(spySend.calledWith('error')).to.be.false;117 });118 it('should delete project and send an error, DELETER', () => {119 const Project = {120 find: () => { },121 deleteOne: () => { }122 }123 const req = {124 query: {}125 }126 const res = {127 status: () => { },128 json: () => { },129 send: () => { }130 }131 const findFake = sinon.fake.yields('', 'project');132 sinon.replace(Project, 'find', findFake);133 const deleteFake = sinon.fake.yields('error', null);134 sinon.replace(Project, 'deleteOne', deleteFake);135 const spySend = sinon.spy(res, 'send');136 controller(Project).deleter(req, res);137 expect(spySend.calledWith('error')).to.be.true;138 });139 it('should delete project and NOT send an error, DELETER', () => {140 const Project = {141 find: () => { },142 deleteOne: () => { }143 }144 const req = {145 query: {}146 }147 const res = {148 status: () => { },149 json: () => { },150 send: () => { }151 }152 const findFake = sinon.fake.yields('', 'project');153 sinon.replace(Project, 'find', findFake);154 const deleteFake = sinon.fake.yields('', 'project');155 sinon.replace(Project, 'deleteOne', deleteFake);156 const spySend = sinon.spy(res, 'send');157 controller(Project).deleter(req, res);158 expect(spySend.calledWith('error')).to.be.false;159 });160 it('should set answers and send an error, PUT', () => {161 const Project = {162 updateOne: () => { }163 }164 const req = {165 body: {166 answers: {}167 }168 }169 const res = {170 status: () => { },171 json: () => { },172 send: () => { }173 }174 const updateFake = sinon.fake.yields('error', null);175 sinon.replace(Project, 'updateOne', updateFake);176 const spySend = sinon.spy(res, 'send');177 controller(Project).put(req, res);178 expect(spySend.calledWith('error')).to.be.true;179 });180 it('should set answers and NOT send an error, PUT', () => {181 const Project = {182 updateOne: () => { }183 }184 const req = {185 body: {186 answers: {}187 }188 }189 const res = {190 status: () => { },191 json: () => { },192 send: () => { }193 }194 const updateFake = sinon.fake.yields('', 'project');195 sinon.replace(Project, 'updateOne', updateFake);196 const spySend = sinon.spy(res, 'send');197 controller(Project).put(req, res);198 expect(spySend.calledWith('error')).to.be.false;199 });200 it('should get scores and send an error, GETSCORES', () => {201 const Project = {202 findOne: () => { },203 updateOne: () => { }204 }205 const req = {206 params: {}207 }208 const res = {209 status: () => { },210 json: () => { },211 send: () => { }212 }213 const project = {214 answers: {}215 }216 const findFake = sinon.fake.yields('error', 'project');217 sinon.replace(Project, 'findOne', findFake);218 const spySend = sinon.spy(res, 'send');219 controller(Project).getScores(req, res);220 expect(spySend.calledWith('error')).to.be.true;221 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var fake = sinon.fake.yields(null, 'hello');2fake((err, data) => {3});4var fake = sinon.fake.yieldsAsync(null, 'hello');5fake((err, data) => {6});7var fake = sinon.fake.yields(null, 'hello');8fake((err, data) => {9});10var fake = sinon.fake.yieldsAsync(null, 'hello');11fake((err, data) => {12});13var fake = sinon.fake.yields(null, 'hello');14fake((err, data) => {15});16var fake = sinon.fake.yieldsAsync(null, 'hello');17fake((err, data) => {18});19var fake = sinon.fake.yields(null, 'hello');20fake((err, data) => {21});22var fake = sinon.fake.yieldsAsync(null, 'hello');23fake((err, data) => {24});25var fake = sinon.fake.yields(null, 'hello');26fake((err, data) => {27});28var fake = sinon.fake.yieldsAsync(null, 'hello');29fake((err, data) => {30});31var fake = sinon.fake.yields(null, 'hello');32fake((err, data) => {33});

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var fake = sinon.fake.yields(null, 'success');3fake(function(err, result) {4 console.log(result);5});6var sinon = require('sinon');7var fake = sinon.fake.yields(null, 'success');8fake(function(err, result) {9 console.log(result);10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var fake = sinon.fake.yields(null, 'success')2fake((err, result) => {3 if (err) {4 console.log(err)5 } else {6 console.log(result)7 }8})9var fake = sinon.fake.throws(new Error('something went wrong'))10fake((err, result) => {11 if (err) {12 console.log(err)13 } else {14 console.log(result)15 }16})17var fake = sinon.fake.returns('success')18fake((err, result) => {19 if (err) {20 console.log(err)21 } else {22 console.log(result)23 }24})25var fake = sinon.fake.resolves('success')26fake((err, result) => {27 if (err) {28 console.log(err)29 } else {30 console.log(result)31 }32})33var fake = sinon.fake.rejects(new Error('something went wrong'))34fake((err, result) => {35 if (err) {36 console.log(err)37 } else {38 console.log(result)39 }40})41var fake = sinon.fake.callThrough((err, result) => {42 if (err) {43 console.log(err)44 } else {45 console.log(result)46 }47})48var fake = sinon.fake.callFake((err, result) => {49 if (err) {50 console.log(err)51 } else {52 console.log(result)53 }54})55var fake = sinon.fake.withArgs(1, 'a').returns('success')56fake(1, 'a')57fake(2, 'a')58fake(1, 'b')59var fake = sinon.fake.withArgs(1, 'a').returns('success')60fake(1, 'a')61fake(2, 'a')62fake(1, 'b')63var fake = sinon.fake.withArgs(1, 'a').returns('success')64fake(1, 'a')65fake(2, 'a')66fake(1,

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var fake = sinon.fake();3fake.yields(new Error('error'), 'result');4fake(function(err, res) {5 console.log(res);6});7var sinon = require('sinon');8var fake = sinon.fake();9fake.yields(new Error('error'), 'result');10fake(function(err, res) {11 console.log(res);12});13var sinon = require('sinon');14var fake = sinon.fake();15fake.yields(new Error('error'), 'result');16fake(function(err, res) {17 console.log(res);18});19var sinon = require('sinon');20var fake = sinon.fake();21fake.yields(new Error('error'), 'result');22fake(function(err, res) {23 console.log(res);24});25var sinon = require('sinon');26var fake = sinon.fake();27fake.yields(new Error('error'), 'result');28fake(function(err, res) {29 console.log(res);30});31var sinon = require('sinon');32var fake = sinon.fake();33fake.yields(new Error('error'), 'result');34fake(function(err, res) {35 console.log(res);36});37var sinon = require('sinon');38var fake = sinon.fake();39fake.yields(new Error('error'), 'result');40fake(function(err, res) {41 console.log(res);42});43var sinon = require('sinon');44var fake = sinon.fake();45fake.yields(new Error('error'), 'result');46fake(function(err, res) {47 console.log(res);48});49var sinon = require('sinon');50var fake = sinon.fake();51fake.yields(new Error('error'), 'result');52fake(function(err, res) {53 console.log(res);54});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', function() {2 it('should call the callback', function(done) {3 var callback = sinon.spy();4 var stub = sinon.stub().yields(null, 'data');5 stub(callback);6 assert(callback.called);7 done();8 });9});10describe('test', function() {11 it('should call the callback', function(done) {12 var callback = sinon.spy();13 var stub = sinon.stub().yields(null, 'data');14 stub(callback);15 assert(callback.calledWith(null, 'data'));16 done();17 });18});19describe('test', function() {20 it('should call the callback', function(done) {21 var callback = sinon.spy();

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var sinon = require('sinon');3var fake = sinon.fake;4var myCallback = function(err, data) {5 if (err) {6 console.log(err);7 return;8 }9 console.log(data);10};11var callback = fake.yields(1, 2);12fs.readFile('test.txt', callback);13var fs = require('fs');14var sinon = require('sinon');15var fake = sinon.fake;16var myCallback = function(err, data) {17 if (err) {18 console.log(err);19 return;20 }21 console.log(data);22};23var callback = fake.yieldsAsync(1, 2);24fs.readFile('test.txt', callback);25var fs = require('fs');26var sinon = require('sinon');27var fake = sinon.fake;28var callback = fake.resolves(1);29callback().then(function(data){30 console.log(data);31});32var fs = require('fs');33var sinon = require('sinon');34var fake = sinon.fake;35var callback = fake.rejects(1);36callback().catch(function(error){37 console.log(error);38});

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var fake = sinon.fake.yields("Error","Data");3fake(function(err,data){4 console.log("Error:" + err);5 console.log("Data:" + data);6});7var sinon = require('sinon');8var fake = sinon.fake.yields("Error","Data","More Data");9fake(function(err,data,moreData){10 console.log("Error:" + err);11 console.log("Data:" + data);12 console.log("More Data:" + moreData);13});14var sinon = require('sinon');15var fake = sinon.fake.yields("Error","Data","More Data");16fake(function(err,data,moreData){17 console.log("Error:" + err);18 console.log("Data:" + data);19 console.log("More Data:" + moreData);20},function(err,data,moreData){21 console.log("Error:" + err);22 console.log("Data:" + data);23 console.log("More Data:" + moreData);24});25var sinon = require('sinon');26var fake = sinon.fake.yields("Error","Data","More Data");27fake(function(err,data,moreData){28 console.log("Error:" + err);29 console.log("Data:" + data);30 console.log("More Data:" + moreData);31},function(err,data,moreData){32 console.log("Error:" + err);33 console.log("Data:" + data);34 console.log("More Data:" + moreData);35},function(err,data,moreData){36 console.log("Error:"

Full Screen

Using AI Code Generation

copy

Full Screen

1var fake = sinon.fake.yields(null, 'success');2fake('hello', 'world');3var fake = sinon.fake.yieldsAsync(null, 'success');4fake('hello', 'world');5var fake = sinon.fake.yieldsOn(null, null, 'success');6fake('hello', 'world');7var fake = sinon.fake.yieldsTo('error', null, 'success');8fake('hello', 'world');9var fake = sinon.fake.yieldsToOn('error', null, null, 'success');10fake('hello', 'world');11var fake = sinon.fake.returns('success');12fake.withArgs('hello', 'world');13fake('hello', 'world');14var fake = sinon.fake.returns('success');15fake.withArgs('hello', 'world').returns('failure

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run sinon 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