How to use sinon.stub method in sinon

Best JavaScript code snippet using sinon

controllers.js

Source:controllers.js Github

copy

Full Screen

...7 describe("create", () => {8 const controllerCreate = require("../../controllers/products/create");9 const response = {};10 const request = {};11 let next = sinon.stub().returns((c) => {});12 describe("erro", () => {13 before(() => {14 request.body = {};15 response.status = sinon.stub().returns(response);16 response.json = sinon.stub().returns();17 });18 after(() => {19 sinon.restore();20 });21 it("sem body chama next", async () => {22 await controllerCreate(request, response, next);23 expect(24 next.calledWith({25 message: "must inform name, qty",26 code: "invalid_data",27 })28 );29 });30 });31 describe("service retorna erro", () => {32 before(() => {33 request.body = { name: "khkj jsh df", quantity: 9 };34 response.status = sinon.stub().returns(response);35 response.json = sinon.stub().returns();36 sinon37 .stub(serviceProduct, "create")38 .resolves({ err: { message: "", code: "" } });39 });40 after(() => {41 sinon.restore();42 });43 it("sem body chama next", async () => {44 await controllerCreate(request, response, next);45 expect(next.calledWith({ err: { message: "", code: "" } })).to.be.equal(46 true47 );48 });49 });50 describe("service retorna ok", () => {51 before(() => {52 request.body = { name: "khkj jsh df", quantity: 9 };53 response.status = sinon.stub().returns(response);54 response.json = sinon.stub().returns();55 sinon56 .stub(serviceProduct, "create")57 .resolves({ name: "khkj jsh df", quantity: 9 });58 });59 after(() => {60 sinon.restore();61 });62 it("chama res", async () => {63 await controllerCreate(request, response, next);64 expect(response.status.calledWith(201)).to.be.equal(true);65 });66 });67 });68 describe("delete", () => {69 const controllerDelete = require("../../controllers/products/delete");70 let next = sinon.stub().returns((c) => {});71 describe("deletar produto erro", () => {72 before(() => {73 request.params = {};74 response.status = sinon.stub().returns(response);75 response.json = sinon.stub().returns();76 sinon.stub(serviceProduct, "remove").resolves({77 err: { message: "Wrong id format", code: "invalid_data" },78 });79 });80 after(() => {81 sinon.restore();82 });83 it("chama next", async () => {84 await controllerDelete(request, response, next);85 expect(86 next.calledOnceWith({87 err: { message: "Wrong id format", code: "invalid_data" },88 })89 ).to.be.equal(true);90 });91 });92 describe("deletar produto ok", () => {93 before(() => {94 request.params = { id: "thisisarealid" };95 response.status = sinon.stub().returns(response);96 response.json = sinon.stub().returns();97 sinon.stub(serviceProduct, "remove").resolves({98 name: "product name",99 quantity: 8,100 });101 });102 after(() => {103 sinon.restore();104 });105 it("retorna status 200", async () => {106 await controllerDelete(request, response, next);107 expect(response.status.calledOnceWith(200)).to.be.equal(true);108 });109 });110 });111 describe("get", () => {112 const controllerGet = require("../../controllers/products/get");113 let next = sinon.stub().returns((c) => {});114 describe("buscar produto erro", () => {115 before(() => {116 request.params = {};117 response.status = sinon.stub().returns(response);118 response.json = sinon.stub().returns();119 sinon.stub(serviceProduct, "remove").resolves({120 err: { message: "Wrong id format", code: "invalid_data" },121 });122 });123 after(() => {124 sinon.restore();125 });126 it("chama next", async () => {127 await controllerGet(request, response, next);128 expect(129 next.calledOnceWith({130 err: { message: "Wrong id format", code: "invalid_data" },131 })132 ).to.be.equal(true);133 });134 });135 describe("buscar produto ok", () => {136 before(() => {137 request.params = { id: "thisisarealid" };138 response.status = sinon.stub().returns(response);139 response.json = sinon.stub().returns();140 sinon.stub(serviceProduct, "get").resolves({141 name: "product name",142 quantity: 8,143 });144 });145 after(() => {146 sinon.restore();147 });148 it("retorna status 200", async () => {149 await controllerGet(request, response, next);150 expect(response.status.calledOnceWith(200)).to.be.equal(true);151 });152 });153 });154 describe("list", () => {155 const controllerList = require("../../controllers/products/list");156 let next = sinon.stub().returns((c) => {});157 describe("buscar produto ok", () => {158 before(() => {159 response.status = sinon.stub().returns(response);160 response.json = sinon.stub().returns();161 sinon.stub(serviceProduct, "list").resolves([162 {163 name: "product name",164 quantity: 8,165 },166 ]);167 });168 after(() => {169 sinon.restore();170 });171 it("retorna status 200", async () => {172 await controllerList(request, response, next);173 expect(response.status.calledOnceWith(200)).to.be.equal(true);174 });175 });176 });177 describe("update", () => {178 const controllerUpdate = require("../../controllers/products/update");179 const response = {};180 const request = {};181 let next = sinon.stub().returns((c) => {});182 describe("erro", () => {183 before(() => {184 request.body = {};185 request.params = {};186 response.status = sinon.stub().returns(response);187 response.json = sinon.stub().returns();188 });189 after(() => {190 sinon.restore();191 });192 it("sem body chama next", async () => {193 await controllerUpdate(request, response, next);194 expect(195 next.calledWith({196 message: "must inform name, qty",197 code: "invalid_data",198 })199 );200 });201 });202 describe("service retorna erro", () => {203 before(() => {204 request.body = { name: "khkj jsh df", quantity: 9 };205 response.status = sinon.stub().returns(response);206 response.json = sinon.stub().returns();207 sinon208 .stub(serviceProduct, "update")209 .resolves({ err: { message: "", code: "" } });210 });211 after(() => {212 sinon.restore();213 });214 it("sem body chama next", async () => {215 await controllerUpdate(request, response, next);216 expect(next.calledWith({ err: { message: "", code: "" } })).to.be.equal(217 true218 );219 });220 });221 describe("service retorna ok", () => {222 before(() => {223 request.body = { name: "khkj jsh df", quantity: 9 };224 response.status = sinon.stub().returns(response);225 response.json = sinon.stub().returns();226 sinon227 .stub(serviceProduct, "update")228 .resolves({ name: "khkj jsh df", quantity: 9 });229 });230 after(() => {231 sinon.restore();232 });233 it("chama res", async () => {234 await controllerUpdate(request, response, next);235 expect(response.status.calledWith(200)).to.be.equal(true);236 });237 });238 });239});240describe("controller sales", () => {241 describe("create", () => {242 const controllerCreate = require("../../controllers/sales/create");243 const response = {};244 const request = {};245 let next = sinon.stub().returns((c) => {});246 describe("erro", () => {247 before(() => {248 request.body = undefined;249 response.status = sinon.stub().returns(response);250 response.json = sinon.stub().returns();251 });252 after(() => {253 sinon.restore();254 });255 it("sem body chama next", async () => {256 await controllerCreate(request, response, next);257 expect(258 next.calledWith({259 message: "Wrong product ID or invalid quantity",260 code: "invalid_data",261 })262 );263 });264 });265 describe("service retorna erro", () => {266 before(() => {267 request.body = { name: "khkj jsh df", quantity: 9 };268 response.status = sinon.stub().returns(response);269 response.json = sinon.stub().returns();270 sinon271 .stub(serviceSales, "create")272 .resolves({ err: { message: "", code: "" } });273 });274 after(() => {275 sinon.restore();276 });277 it("sem body chama next", async () => {278 await controllerCreate(request, response, next);279 expect(next.calledWith({ err: { message: "", code: "" } })).to.be.equal(280 true281 );282 });283 });284 describe("service retorna ok", () => {285 before(() => {286 request.body = { name: "khkj jsh df", quantity: 9 };287 response.status = sinon.stub().returns(response);288 response.json = sinon.stub().returns();289 sinon290 .stub(serviceSales, "create")291 .resolves({ name: "khkj jsh df", quantity: 9 });292 });293 after(() => {294 sinon.restore();295 });296 it("chama res", async () => {297 await controllerCreate(request, response, next);298 expect(response.status.calledWith(200)).to.be.equal(true);299 });300 });301 });302 describe("delete", () => {303 const controllerDelete = require("../../controllers/sales/delete");304 let next = sinon.stub().returns((c) => {});305 describe("deletar sale erro", () => {306 before(() => {307 request.params = {};308 response.status = sinon.stub().returns(response);309 response.json = sinon.stub().returns();310 sinon.stub(serviceSales, "remove").resolves({311 err: { message: "Wrong id format", code: "invalid_data" },312 });313 });314 after(() => {315 sinon.restore();316 });317 it("chama next", async () => {318 await controllerDelete(request, response, next);319 expect(320 next.calledOnceWith({321 err: { message: "Wrong id format", code: "invalid_data" },322 })323 ).to.be.equal(true);324 });325 });326 describe("deletar sale ok", () => {327 before(() => {328 request.params = { id: "thisisarealid" };329 response.status = sinon.stub().returns(response);330 response.json = sinon.stub().returns();331 sinon.stub(serviceSales, "remove").resolves({332 name: "product name",333 quantity: 8,334 });335 });336 after(() => {337 sinon.restore();338 });339 it("retorna status 200", async () => {340 await controllerDelete(request, response, next);341 expect(response.status.calledOnceWith(200)).to.be.equal(true);342 });343 });344 });345 describe("get", () => {346 const controllerGet = require("../../controllers/sales/get");347 let next = sinon.stub().returns((c) => {});348 describe("buscar produto sem id", () => {349 const response = {};350 const request = {};351 before(() => {352 request.params = {};353 response.status = sinon.stub().returns(response);354 response.json = sinon.stub().returns();355 });356 after(() => {357 sinon.restore();358 });359 it("chama next", async () => {360 await controllerGet(request, response, next);361 expect(362 next.calledOnceWith({363 err: { status: 404, code: "not_found" },364 })365 ).to.be.equal(true);366 });367 });368 describe("buscar produto erro", () => {369 before(() => {370 request.params = { id: "123" };371 response.status = sinon.stub().returns(response);372 response.json = sinon.stub().returns();373 sinon.stub(serviceSales, "get").resolves({374 err: { message: "Wrong id format", code: "invalid_data" },375 });376 });377 after(() => {378 sinon.restore();379 });380 it("chama next", async () => {381 await controllerGet(request, response, next);382 expect(383 next.calledOnceWith({384 err: { message: "Wrong id format", code: "invalid_data" },385 })386 ).to.be.equal(true);387 });388 });389 describe("buscar produto ok", () => {390 before(() => {391 request.params = { id: "thisisarealid" };392 response.status = sinon.stub().returns(response);393 response.json = sinon.stub().returns();394 sinon.stub(serviceProduct, "get").resolves({395 name: "product name",396 quantity: 8,397 });398 });399 after(() => {400 sinon.restore();401 });402 it("retorna status 200", async () => {403 await controllerGet(request, response, next);404 expect(response.status.calledOnceWith(200)).to.be.equal(true);405 });406 });407 });408 describe("list", () => {409 const controllerList = require("../../controllers/products/list");410 let next = sinon.stub().returns((c) => {});411 describe("buscar produto ok", () => {412 before(() => {413 response.status = sinon.stub().returns(response);414 response.json = sinon.stub().returns();415 sinon.stub(serviceProduct, "list").resolves([416 {417 name: "product name",418 quantity: 8,419 },420 ]);421 });422 after(() => {423 sinon.restore();424 });425 it("retorna status 200", async () => {426 await controllerList(request, response, next);427 expect(response.status.calledOnceWith(200)).to.be.equal(true);428 });429 });430 });431 describe("update", () => {432 const controllerUpdate = require("../../controllers/products/update");433 const response = {};434 const request = {};435 let next = sinon.stub().returns((c) => {});436 describe("erro", () => {437 before(() => {438 request.body = {};439 request.params = {};440 response.status = sinon.stub().returns(response);441 response.json = sinon.stub().returns();442 });443 after(() => {444 sinon.restore();445 });446 it("sem body chama next", async () => {447 await controllerUpdate(request, response, next);448 expect(449 next.calledWith({450 message: "must inform name, qty",451 code: "invalid_data",452 })453 );454 });455 });456 describe("service retorna erro", () => {457 before(() => {458 request.body = { name: "khkj jsh df", quantity: 9 };459 response.status = sinon.stub().returns(response);460 response.json = sinon.stub().returns();461 sinon462 .stub(serviceProduct, "update")463 .resolves({ err: { message: "", code: "" } });464 });465 after(() => {466 sinon.restore();467 });468 it("sem body chama next", async () => {469 await controllerUpdate(request, response, next);470 expect(next.calledWith({ err: { message: "", code: "" } })).to.be.equal(471 true472 );473 });474 });475 describe("service retorna ok", () => {476 before(() => {477 request.body = { name: "khkj jsh df", quantity: 9 };478 response.status = sinon.stub().returns(response);479 response.json = sinon.stub().returns();480 sinon481 .stub(serviceProduct, "update")482 .resolves({ name: "khkj jsh df", quantity: 9 });483 });484 after(() => {485 sinon.restore();486 });487 it("chama res", async () => {488 await controllerUpdate(request, response, next);489 expect(response.status.calledWith(200)).to.be.equal(true);490 });491 });492 });493});

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

...28 erizoController: {report: {}}29 });30 module.exports.spawn = {31 stdout: {32 setEncoding: sinon.stub(),33 on: sinon.stub()34 },35 stderr: {36 setEncoding: sinon.stub(),37 on: sinon.stub()38 },39 on: sinon.stub(),40 unref: sinon.stub(),41 kill: sinon.stub()42 };43 module.exports.childProcess = createMock('child_process', {44 spawn: sinon.stub().returns(module.exports.spawn)45 });46 module.exports.ec2Client = {47 call: sinon.stub()48 };49 module.exports.awslib = createMock('aws-lib', {50 createEC2Client: sinon.stub().returns(module.exports.ec2Client)51 });52 module.exports.os = createMock('os', {53 networkInterfaces: sinon.stub()54 });55 module.exports.fs = createMock('fs', {56 openSync: sinon.stub(),57 close: sinon.stub()58 });59 module.exports.Server = {60 listen: sinon.stub()61 };62 module.exports.signature = {63 update: sinon.stub(),64 digest: sinon.stub()65 };66 module.exports.crypto = createMock('crypto', {67 createHmac: sinon.stub().returns(module.exports.signature),68 randomBytes: sinon.stub().returns(new Buffer(16))69 });70 module.exports.http = createMock('http', {71 createServer: sinon.stub().returns(module.exports.Server),72 close: sinon.stub()73 });74 module.exports.socketInstance = {75 conn: {transport: {socket: {internalOnClose: undefined}}},76 disconnect: sinon.stub(),77 emit: sinon.stub(),78 on: sinon.stub()79 };80 module.exports.socketIoInstance = {81 set: sinon.stub(),82 sockets: {83 on: sinon.stub(),84 socket: sinon.stub().returns(module.exports.socketInstance), // v0.985 sockets:{'streamId1': module.exports.socketInstance, // v2.0.386 undefined: module.exports.socketInstance},87 indexOf: sinon.stub()88 }89 };90 module.exports.socketIo = createMock('socket.io', {91 listen: sinon.stub().returns(module.exports.socketIoInstance),92 close: sinon.stub()93 });94 module.exports.amqper = createMock('../common/amqper', {95 connect: sinon.stub().callsArg(0),96 broadcast: sinon.stub(),97 setPublicRPC: sinon.stub(),98 callRpc: sinon.stub(),99 bind: sinon.stub(),100 bindBroadcast: sinon.stub()101 });102 module.exports.ErizoAgentReporterInstance = {103 getErizoAgent: sinon.stub()104 };105 module.exports.erizoAgentReporter = createMock('../erizoAgent/erizoAgentReporter', {106 Reporter: sinon.stub().returns(module.exports.ErizoAgentReporterInstance)107 });108 module.exports.OneToManyProcessor = {109 addExternalOutput: sinon.stub(),110 setExternalPublisher: sinon.stub(),111 setPublisher: sinon.stub(),112 addSubscriber: sinon.stub(),113 removeSubscriber: sinon.stub(),114 close: sinon.stub(),115 };116 module.exports.ConnectionDescription = {117 close: sinon.stub(),118 setRtcpMux: sinon.stub(),119 setProfile: sinon.stub(),120 setBundle: sinon.stub(),121 setAudioAndVideo: sinon.stub(),122 setVideoSsrcList: sinon.stub(),123 postProcessInfo: sinon.stub(),124 hasAudio: sinon.stub(),125 hasVideo: sinon.stub(),126 };127 module.exports.WebRtcConnection = {128 init: sinon.stub(),129 close: sinon.stub(),130 createOffer: sinon.stub(),131 setRemoteSdp: sinon.stub(),132 setRemoteDescription: sinon.stub(),133 getLocalDescription: sinon.stub().returns(module.exports.ConnectionDescription),134 addRemoteCandidate: sinon.stub(),135 addMediaStream: sinon.stub(),136 removeMediaStream: sinon.stub(),137 };138 module.exports.MediaStream = {139 minVideoBW: '',140 scheme: '',141 periodicPlis: '',142 close: sinon.stub(),143 setAudioReceiver: sinon.stub(),144 setVideoReceiver: sinon.stub(),145 setMaxVideoBW: sinon.stub(),146 getStats: sinon.stub(),147 getPeriodicStats: sinon.stub(),148 generatePLIPacket: sinon.stub(),149 setSlideShowMode: sinon.stub(),150 muteStream: sinon.stub(),151 onMediaStreamEvent: sinon.stub(),152 };153 module.exports.ExternalInput = {154 init: sinon.stub(),155 setAudioReceiver: sinon.stub(),156 setVideoReceiver: sinon.stub()157 };158 module.exports.ExternalOutput = {159 init: sinon.stub(),160 close: sinon.stub()161 };162 module.exports.erizoAPI = createMock('../../erizoAPI/build/Release/addon', {163 OneToManyProcessor: sinon.stub().returns(module.exports.OneToManyProcessor),164 ConnectionDescription: sinon.stub().returns(module.exports.ConnectionDescription),165 WebRtcConnection: sinon.stub().returns(module.exports.WebRtcConnection),166 MediaStream: sinon.stub().returns(module.exports.MediaStream),167 ExternalInput: sinon.stub().returns(module.exports.ExternalInput),168 ExternalOutput: sinon.stub().returns(module.exports.ExternalOutput)169 });170 module.exports.roomControllerInstance = {171 addEventListener: sinon.stub(),172 addExternalInput: sinon.stub(),173 addExternalOutput: sinon.stub(),174 processSignaling: sinon.stub(),175 addPublisher: sinon.stub(),176 addSubscriber: sinon.stub(),177 removePublisher: sinon.stub(),178 removeSubscriber: sinon.stub(),179 removeSubscriptions: sinon.stub(),180 removeExternalOutput: sinon.stub()181 };182 module.exports.roomController = createMock('../erizoController/roomController', {183 RoomController: sinon.stub().returns(module.exports.roomControllerInstance)184 });185 module.exports.ecchInstance = {186 getErizoJS: sinon.stub(),187 deleteErizoJS: sinon.stub()188 };189 module.exports.ecch = createMock('../erizoController/ecCloudHandler', {190 EcCloudHandler: sinon.stub().returns(module.exports.ecchInstance)191 });192};...

Full Screen

Full Screen

kuzzle.mock.js

Source:kuzzle.mock.js Github

copy

Full Screen

...20 // we need a deep copy here21 this.config = JSON.parse(JSON.stringify(config));22 // ========== EVENTS ==========23 // emit + pipe mocks24 sinon.stub(this, 'pipe').callsFake((...args) => {25 if (typeof args[args.length - 1] !== 'function') {26 return Bluebird.resolve(...args.slice(1));27 }28 const cb = args.pop();29 cb(null, ...args.slice(1));30 });31 sinon.stub(this, 'ask').resolves();32 sinon.stub(this, 'call');33 sinon.stub(this, 'once');34 sinon.spy(this, 'emit');35 sinon.spy(this, 'registerPluginHook');36 sinon.spy(this, 'registerPluginPipe');37 sinon.spy(this, 'onCall');38 sinon.spy(this, 'onAsk');39 sinon.spy(this, 'on');40 sinon.spy(this, 'onPipe');41 // ============================42 this.log = {43 error: sinon.stub(),44 warn: sinon.stub(),45 info: sinon.stub(),46 silly: sinon.stub(),47 debug: sinon.stub(),48 verbose: sinon.stub()49 };50 this.koncorde = {51 getFilterIds: sinon.stub().returns([]),52 getIndexes: sinon.stub().returns([]),53 hasFilterId: sinon.stub().returns(false),54 normalize: sinon.stub().returns({ id: 'foobar' }),55 register: sinon.stub().returns('foobar'),56 remove: sinon.stub(),57 store: sinon.stub().returns('foobar'),58 test: sinon.stub().returns([]),59 validate: sinon.stub(),60 };61 this.entryPoint = {62 dispatch: sinon.spy(),63 init: sinon.stub(),64 startListening: sinon.spy(),65 joinChannel: sinon.spy(),66 leaveChannel: sinon.spy()67 };68 this.funnel = {69 controllers: new Map(),70 init: sinon.spy(),71 loadPluginControllers: sinon.spy(),72 getRequestSlot: sinon.stub().returns(true),73 handleErrorDump: sinon.spy(),74 execute: sinon.stub(),75 mExecute: sinon.stub(),76 processRequest: sinon.stub().resolves(),77 checkRights: sinon.stub(),78 getEventName: sinon.spy(),79 executePluginRequest: sinon.stub().resolves(),80 isNativeController: sinon.stub()81 };82 this.dumpGenerator = {83 dump: sinon.stub().resolves()84 };85 this.shutdown = sinon.stub();86 const InternalIndexHandlerMock = require('./internalIndexHandler.mock');87 this.internalIndex = new InternalIndexHandlerMock();88 this.passport = {89 use: sinon.stub(),90 unuse: sinon.stub(),91 authenticate: sinon.stub().resolves({}),92 injectAuthenticateOptions: sinon.stub()93 };94 this.pluginsManager = {95 controllers: new Map(),96 init: sinon.stub().resolves(),97 plugins: [],98 run: sinon.stub().resolves(),99 getPluginsDescription: sinon.stub().returns({}),100 listStrategies: sinon.stub().returns([]),101 getActions: sinon.stub(),102 getControllerNames: sinon.stub(),103 isController: sinon.stub(),104 isAction: sinon.stub(),105 exists: sinon.stub(),106 getStrategyFields: sinon.stub().resolves(),107 getStrategyMethod: sinon.stub().returns(sinon.stub()),108 hasStrategyMethod: sinon.stub().returns(false),109 strategies: {},110 registerStrategy: sinon.stub(),111 unregisterStrategy: sinon.stub(),112 application: {113 info: sinon.stub(),114 name: 'my-app',115 },116 routes: [],117 loadedPlugins: []118 };119 this.rootPath = '/kuzzle';120 this.router = {121 connections: new Map(),122 execute: sinon.stub().resolves(foo),123 isConnectionAlive: sinon.stub().returns(true),124 init: sinon.spy(),125 newConnection: sinon.stub().resolves(foo),126 removeConnection: sinon.spy(),127 http: {128 route: sinon.stub()129 }130 };131 this.start = sinon.stub().resolves();132 this.statistics = {133 completedRequest: sinon.spy(),134 newConnection: sinon.stub(),135 failedRequest: sinon.spy(),136 getAllStats: sinon.stub().resolves(foo),137 getLastStats: sinon.stub().resolves(foo),138 getStats: sinon.stub().resolves(foo),139 init: sinon.spy(),140 dropConnection: sinon.stub(),141 startRequest: sinon.spy()142 };143 this.tokenManager = {144 init: sinon.stub().resolves(),145 expire: sinon.stub(),146 getConnectedUserToken: sinon.stub(),147 link: sinon.stub(),148 refresh: sinon.stub(),149 unlink: sinon.stub(),150 getKuidFromConnection: sinon.stub(),151 removeConnection: sinon.stub().resolves(),152 };153 this.validation = {154 addType: sinon.spy(),155 curateSpecification: sinon.stub().resolves(),156 init: sinon.spy(),157 validateFormat: sinon.stub().resolves({ isValid: false }),158 validate: sinon.stub().callsFake((...args) => Bluebird.resolve(args[0]))159 };160 this.vault = {161 init: sinon.stub(),162 prepareCrypto: sinon.stub(),163 secrets: {164 aws: {165 secretKeyId: 'the cake is a lie'166 },167 kuzzleApi: 'the spoon does not exist'168 }169 };170 this.adminExists = sinon.stub().resolves();171 this.dump = sinon.stub().resolves();172 this.asyncStore = {173 run: sinon.stub().yields(),174 set: sinon.stub(),175 exists: sinon.stub(),176 has: sinon.stub(),177 get: sinon.stub(),178 };179 this.start = sinon.stub().resolves();180 this.hash = sinon.stub().callsFake(obj => JSON.stringify(obj));181 this.running = sinon.stub().returns(false);182 }183}...

Full Screen

Full Screen

productDecoratorsMock.js

Source:productDecoratorsMock.js Github

copy

Full Screen

1'use strict';2var proxyquire = require('proxyquire').noCallThru().noPreserveCache();3var sinon = require('sinon');4var stubBase = sinon.stub();5var stubPrice = sinon.stub();6var stubImages = sinon.stub();7var stubAvailability = sinon.stub();8var stubDescription = sinon.stub();9var stubSearchPrice = sinon.stub();10var stubPromotions = sinon.stub();11var stubQuantity = sinon.stub();12var stubQuantitySelector = sinon.stub();13var stubRatings = sinon.stub();14var stubSizeChart = sinon.stub();15var stubVariationAttributes = sinon.stub();16var stubSearchVariationAttributes = sinon.stub();17var stubAttributes = sinon.stub();18var stubOptions = sinon.stub();19var stubCurrentUrl = sinon.stub();20var stubReadyToOrder = sinon.stub();21var stubOnline = sinon.stub();22var stubSetReadyToOrder = sinon.stub();23var stubBundleReadyToOrder = sinon.stub();24var stubSetIndividualProducts = sinon.stub();25var stubSetProductsCollection = sinon.stub();26var stubBundledProducts = sinon.stub();27var stubBonusUnitPrice = sinon.stub();28var stubRaw = sinon.stub();29var stubPageMetaData = sinon.stub();30var stubTemplate = sinon.stub();31function proxyModel() {32 return {33 mocks: proxyquire('../../cartridges/app_storefront_base/cartridge/models/product/decorators/index', {34 '*/cartridge/models/product/decorators/base': stubBase,35 '*/cartridge/models/product/decorators/availability': stubAvailability,36 '*/cartridge/models/product/decorators/description': stubDescription,37 '*/cartridge/models/product/decorators/images': stubImages,38 '*/cartridge/models/product/decorators/price': stubPrice,39 '*/cartridge/models/product/decorators/searchPrice': stubSearchPrice,40 '*/cartridge/models/product/decorators/promotions': stubPromotions,41 '*/cartridge/models/product/decorators/quantity': stubQuantity,42 '*/cartridge/models/product/decorators/quantitySelector': stubQuantitySelector,43 '*/cartridge/models/product/decorators/ratings': stubRatings,44 '*/cartridge/models/product/decorators/sizeChart': stubSizeChart,...

Full Screen

Full Screen

share.js

Source:share.js Github

copy

Full Screen

...46 });47};48export function stubCommands() {49 beforeEach('set up stubs', function() {50 this.addAll = sinon.stub(addAll, 'default');51 this.add = sinon.stub(add, 'default');52 this.bump = sinon.stub(bump, 'default');53 this.check = sinon.stub(check, 'default');54 this.create = sinon.stub(create, 'default');55 this.queryDeployment = sinon.stub(queryDeployment, 'default');56 this.querySignedDeployment = sinon.stub(querySignedDeployment, 'default');57 this.freeze = sinon.stub(freeze, 'default');58 this.init = sinon.stub(init, 'default');59 this.link = sinon.stub(link, 'default');60 this.unlink = sinon.stub(unlink, 'default');61 this.publish = sinon.stub(publish, 'default');62 this.push = sinon.stub(push, 'default');63 this.remove = sinon.stub(remove, 'default');64 this.session = sinon.stub(session, 'default');65 this.update = sinon.stub(update, 'default');66 this.setAdmin = sinon.stub(setAdmin, 'default');67 this.unpack = sinon.stub(unpack, 'default');68 this.transfer = sinon.stub(transfer, 'default');69 this.balance = sinon.stub(balance, 'default');70 this.sendTx = sinon.stub(sendTx, 'default');71 this.call = sinon.stub(call, 'default');72 this.accounts = sinon.stub(accounts, 'default');73 this.compiler = sinon.stub(Compiler, 'compile');74 this.transpiler = sinon.stub(transpiler, 'transpileAndSave');75 this.initializer = sinon.stub(ConfigManager, 'initNetworkConfiguration').callsFake(function(options) {76 ConfigManager.initStaticConfiguration();77 const { network, from } = Session.getOptions(options);78 const txParams = from ? { from } : {};79 return { network, txParams };80 });81 this.getManifestVersion = sinon.stub(NetworkFile, 'getManifestVersion').returns('2.2');82 this.projectFile = sinon.stub(ProjectFile.prototype, 'exists').returns(true);83 const projectFile = new ProjectFile('mocks/mock-stdlib/zos.json');84 this.dependency = sinon.stub(Dependency.prototype, 'projectFile').get(function getterFn() {85 return projectFile;86 });87 this.report = sinon.stub(Telemetry, 'report');88 });89 afterEach('restore', function() {90 sinon.restore();91 program.parseReset();92 });93}94export function itShouldParse(name, cmd, args, cb) {95 it(name, function(done) {96 this[cmd].onFirstCall().callsFake(() => {97 let err;98 try {99 cb(this[cmd]);100 } catch (e) {101 err = e;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var myObj = {4 myMethod: function (callback) {5 callback();6 }7};8var callback = sinon.stub();9myObj.myMethod(callback);10assert(callback.called);11var sinon = require('sinon');12var assert = require('assert');13var myObj = {14 myMethod: function (callback) {15 callback();16 }17};18var spy = sinon.spy();19myObj.myMethod(spy);20assert(spy.called);21var sinon = require('sinon');22var assert = require('assert');23var myObj = {24 myMethod: function (callback) {25 callback();26 }27};28var mockObj = sinon.mock(myObj);29mockObj.expects('myMethod').once();30myObj.myMethod(function () { });31mockObj.verify();32var sinon = require('sinon');33var assert = require('assert');34var myObj = {35 myMethod: function (callback) {36 callback();37 }38};39var stub = sinon.stub(myObj, 'myMethod');40myObj.myMethod(function () { });41assert(stub.called);42var sinon = require('sinon');43var assert = require('assert');44var myObj = {45 myMethod: function (callback) {46 callback();47 }48};49var spy = sinon.spy(myObj, 'myMethod');50myObj.myMethod(function () { });51assert(spy.called);52var sinon = require('sinon');53var assert = require('assert');54var myObj = {55 myMethod: function (callback) {56 callback();57 }58};59var mockObj = sinon.mock(myObj);60mockObj.expects('myMethod').once();61myObj.myMethod(function () { });62mockObj.verify();63var sinon = require('sinon');64var assert = require('assert');65var myObj = {66 myMethod: function (callback) {67 callback();68 }69};70var stub = sinon.stub(myObj, 'myMethod');71myObj.myMethod(function () { });72assert(stub.called);73var sinon = require('sinon');74var assert = require('

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('chai').assert;3var myModule = require('./myModule');4describe('myModule', function() {5 it('should call the callback', function() {6 var callback = sinon.spy();7 myModule.foo(callback);8 assert(callback.called);9 });10});11var foo = function(callback) {12 callback();13};14module.exports = {15};16var sinon = require('sinon');17var assert = require('chai').assert;18var myModule = require('./myModule');19describe('myModule', function() {20 it('should call the callback', function() {21 var callback = sinon.spy();22 myModule.foo(callback);23 assert(callback.called);24 });25});26var foo = function(callback) {27 callback();28};29module.exports = {30};31var sinon = require('sinon');32var assert = require('chai').assert;33var myModule = require('./myModule');34describe('myModule', function() {35 it('should call the callback', function() {36 var callback = sinon.spy();37 myModule.foo(callback);38 assert(callback.called);39 });40});41var foo = function(callback) {42 callback();43};44module.exports = {45};46var sinon = require('sinon');47var assert = require('chai').assert;48var myModule = require('./myModule');49describe('myModule', function() {50 it('should call the callback', function() {51 var callback = sinon.spy();52 myModule.foo(callback);53 assert(callback.called);54 });55});56var foo = function(callback) {57 callback();58};59module.exports = {60};61var sinon = require('sinon');62var assert = require('chai').assert;

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var chai = require('chai');3var expect = chai.expect;4var assert = chai.assert;5var should = chai.should;6var request = require('request');7var sinonStubPromise = require('sinon-stub-promise');8sinonStubPromise(sinon);9var rp = require('request-promise');10describe('Stubbing request using sinon', function () {11 it('should stub request', function () {12 var stub = sinon.stub(request, 'get').yields(null, null, 'Hello World');13 expect(body).to.equal('Hello World');14 });15 stub.restore();16 });17 it('should stub request with promise', function () {18 var stub = sinon.stub(request, 'get').returnsPromise();19 stub.resolves('Hello World');20 expect(body).to.equal('Hello World');21 });22 stub.restore();23 });24 it('should stub request with promise using request-promise', function () {25 var stub = sinon.stub(rp, 'get').returnsPromise();26 stub.resolves('Hello World');27 expect(response).to.equal('Hello World');28 });29 stub.restore();30 });31});32var sinon = require('sinon');33var chai = require('chai');34var expect = chai.expect;35var assert = chai.assert;36var should = chai.should;37var request = require('request');38var sinonStubPromise = require('sinon-stub-promise');39sinonStubPromise(sinon);40var rp = require('request-promise');41describe('Mocking request using sinon', function () {42 it('should mock request', function () {43 var mock = sinon.mock(request);44 expectation.verify();45 mock.restore();46 });47 it('should mock request with promise', function () {48 var mock = sinon.mock(request);49 expectation.resolves('Hello World');50 request.get('

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var myObj = {3 add: function(a, b) {4 return a + b;5 }6};7var stub = sinon.stub(myObj, "add");8stub.returns(15);9assert.equal(myObj.add(10, 10), 15);10assert.equal(stub.callCount, 1);11assert.equal(stub.calledWith(10, 10), true);12assert.equal(stub.firstCall.args[0], 10);13assert.equal(stub.firstCall.args[1], 10);14stub.restore();15var sinon = require('sinon');16var assert = require('assert');17var myObj = {18 add: function(a, b) {19 return a + b;20 }21};22var spy = sinon.spy(myObj, "add");23assert.equal(myObj.add(10, 10), 20);24assert.equal(spy.callCount, 1);25assert.equal(spy.calledWith(10, 10), true);26assert.equal(spy.firstCall.args[0], 10);27assert.equal(spy.firstCall.args[1], 10);28spy.restore();

Full Screen

Using AI Code Generation

copy

Full Screen

1const sinon = require('sinon');2const assert = require('assert');3const myDatabase = require('../database');4const myFunction = require('../function');5describe('test myFunction', () => {6 it('should call myDatabase.save with correct arguments', () => {7 const stub = sinon.stub(myDatabase, 'save');8 myFunction();9 assert(stub.calledWith('test'));10 stub.restore();11 });12});

Full Screen

Using AI Code Generation

copy

Full Screen

1const sinon = require('sinon');2const chai = require('chai');3const assert = chai.assert;4const expect = chai.expect;5const should = chai.should();6const myModule = require('./myModule.js');7const myModule2 = require('./myModule2.js');8const myModule3 = require('./myModule3.js');9const myModule4 = require('./myModule4.js');10const myModule5 = require('./myModule5.js');11const myModule6 = require('./myModule6.js');12const myModule7 = require('./myModule7.js');13const myModule8 = require('./myModule8.js');14const myModule9 = require('./myModule9.js');15const myModule10 = require('./myModule10.js');16const myModule11 = require('./myModule11.js');17const myModule12 = require('./myModule12.js');18const myModule13 = require('./myModule13.js');19const myModule14 = require('./myModule14.js');20const myModule15 = require('./myModule15.js');21const myModule16 = require('./myModule16.js');22const myModule17 = require('./myModule17.js');23const myModule18 = require('./myModule18.js');24const myModule19 = require('./myModule19.js');25const myModule20 = require('./myModule20.js');26const myModule21 = require('./myModule21.js');27const myModule22 = require('./myModule22.js');28const myModule23 = require('./myModule23.js');29const myModule24 = require('./myModule24.js');30const myModule25 = require('./myModule25.js');31const myModule26 = require('./myModule26.js');32const myModule27 = require('./myModule27.js');33const myModule28 = require('./myModule28.js');34const myModule29 = require('./myModule29.js');35const myModule30 = require('./myModule30.js');36const myModule31 = require('./myModule31.js');37const myModule32 = require('./myModule32.js');38const myModule33 = require('./myModule33.js');39const myModule34 = require('./myModule34.js');40const myModule35 = require('./myModule35.js');41const myModule36 = require('./myModule36.js');42const myModule37 = require('./myModule37.js');43const myModule38 = require('./myModule

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