How to use createStubInstance method in sinon

Best JavaScript code snippet using sinon

request.js

Source:request.js Github

copy

Full Screen

...24 let nexmo;25 let request;26 let response;27 beforeEach(() => {28 client = sinon.createStubInstance(Client);29 config = sinon.createStubInstance(Config);30 response = sinon.createStubInstance(Response);31 request = new Request(config, client, response);32 });33 describe('.accountSetup', () => {34 it('should verifiy the credentials', test(function(){35 nexmo = {};36 nexmo.account = sinon.createStubInstance(Account);37 client.instanceWith.returns(nexmo);38 response.accountSetup.returns(()=>{});39 request.accountSetup('123', 'abc', false);40 expect(nexmo.account.checkBalance).to.have.been.called;41 expect(response.accountSetup).to.have.been.called;42 }));43 });44 describe('.accountInfo', () => {45 it('should read the credentials', test(function() {46 nexmo = { credentials: 'credentials' };47 client.instance.returns(nexmo);48 request.accountInfo();49 expect(response.accountInfo).to.have.been.calledWith({ credentials: 'credentials' });50 }));51 });52 describe('.accountBalance', () => {53 it('should call nexmo.account.checkBalance', test(function() {54 nexmo = {};55 nexmo.account = sinon.createStubInstance(Account);56 client.instance.returns(nexmo);57 request.accountBalance();58 expect(nexmo.account.checkBalance).to.have.been.called;59 }));60 });61 describe('.priceVoice', () => {62 it('should call nexmo.number.getPhonePricing', test(function() {63 nexmo = {};64 nexmo.number = sinon.createStubInstance(Number);65 client.instance.returns(nexmo);66 request.priceVoice();67 expect(nexmo.number.getPhonePricing).to.have.been.called;68 }));69 it('should accept a + in the number', test(function() {70 nexmo = {};71 nexmo.number = sinon.createStubInstance(Number);72 client.instance.returns(nexmo);73 request.priceVoice('+123123123123');74 expect(nexmo.number.getPhonePricing).to.have.been.calledWith('voice', '123123123123');75 }));76 });77 describe('.priceSms', () => {78 it('should call nexmo.number.getPhonePricing', test(function() {79 nexmo = {};80 nexmo.number = sinon.createStubInstance(Number);81 client.instance.returns(nexmo);82 request.priceSms();83 expect(nexmo.number.getPhonePricing).to.have.been.called;84 }));85 });86 describe('.priceCountry', () => {87 it('should call nexmo.number.getPricing', test(function() {88 nexmo = {};89 nexmo.number = sinon.createStubInstance(Number);90 client.instance.returns(nexmo);91 request.priceCountry();92 expect(nexmo.number.getPricing).to.have.been.called;93 }));94 });95 describe('.numbersList', () => {96 it('should call nexmo.number.get', test(function() {97 nexmo = {};98 nexmo.number = sinon.createStubInstance(Number);99 client.instance.returns(nexmo);100 response.numbersList.returns(()=>{});101 request.numbersList({});102 expect(nexmo.number.get).to.have.been.called;103 expect(nexmo.number.get).to.have.been.calledWith({ size: 100 });104 }));105 it('should parse a page flag', test(function() {106 nexmo = {};107 nexmo.number = sinon.createStubInstance(Number);108 client.instance.returns(nexmo);109 response.numbersList.returns(()=>{});110 request.numbersList({ page: 2 });111 expect(nexmo.number.get).to.have.been.calledWith({ index: 2, size: 100 });112 }));113 it('should parse a size flag', test(function() {114 nexmo = {};115 nexmo.number = sinon.createStubInstance(Number);116 client.instance.returns(nexmo);117 response.numbersList.returns(()=>{});118 request.numbersList({ size: 25 });119 expect(nexmo.number.get).to.have.been.calledWith({ size: 25 });120 }));121 it('should handle search with a default search_pattern of 1', test(function() {122 nexmo = {};123 nexmo.number = sinon.createStubInstance(Number);124 client.instance.returns(nexmo);125 response.numbersList.returns(()=>{});126 const pattern = '123';127 request.numbersList({ pattern: pattern });128 expect(nexmo.number.get).to.have.been.calledWith({ pattern: pattern, search_pattern: 1, size: 100 });129 }));130 it('should handle search with a search_pattern of 2 when * is the first pattern char', test(function() {131 nexmo = {};132 nexmo.number = sinon.createStubInstance(Number);133 client.instance.returns(nexmo);134 response.numbersList.returns(()=>{});135 const pattern = '*123';136 request.numbersList({ pattern: pattern });137 expect(nexmo.number.get).to.have.been.calledWith({ pattern: pattern, search_pattern: 2, size: 100 });138 }));139 it('should handle search with a search_pattern of 0 when * is the last pattern char', test(function() {140 nexmo = {};141 nexmo.number = sinon.createStubInstance(Number);142 client.instance.returns(nexmo);143 response.numbersList.returns(()=>{});144 const pattern = '123*';145 request.numbersList({ pattern: pattern });146 expect(nexmo.number.get).to.have.been.calledWith({ pattern: pattern, search_pattern: 0, size: 100 });147 }));148 });149 describe('.numberSearch', () => {150 it('should call nexmo.number.search', test(function() {151 nexmo = {};152 nexmo.number = sinon.createStubInstance(Number);153 client.instance.returns(nexmo);154 response.numberSearch.returns(()=>{});155 request.numberSearch('GB', {});156 expect(nexmo.number.search).to.have.been.calledWith('GB', { features: [], size: 100 });157 }));158 it('should parse a voice flag', test(function() {159 nexmo = {};160 nexmo.number = sinon.createStubInstance(Number);161 client.instance.returns(nexmo);162 response.numberSearch.returns(()=>{});163 request.numberSearch('GB', { voice: true });164 expect(nexmo.number.search).to.have.been.calledWith('GB', { features: ['VOICE'], size: 100 });165 }));166 it('should parse a sms flag', test(function() {167 nexmo = {};168 nexmo.number = sinon.createStubInstance(Number);169 client.instance.returns(nexmo);170 response.numberSearch.returns(()=>{});171 request.numberSearch('GB', { sms: true });172 expect(nexmo.number.search).to.have.been.calledWith('GB', { features: ['SMS'], size: 100 });173 }));174 it('should parse both the sms and voice flag', test(function() {175 nexmo = {};176 nexmo.number = sinon.createStubInstance(Number);177 client.instance.returns(nexmo);178 response.numberSearch.returns(()=>{});179 request.numberSearch('GB', { sms: true, voice: true });180 expect(nexmo.number.search).to.have.been.calledWith('GB', { features: ['VOICE','SMS'], size: 100 });181 }));182 it('should parse a page flag', test(function() {183 nexmo = {};184 nexmo.number = sinon.createStubInstance(Number);185 client.instance.returns(nexmo);186 response.numberSearch.returns(()=>{});187 request.numberSearch('GB', { page: 2 });188 expect(nexmo.number.search).to.have.been.calledWith('GB', { features: [], index: 2, size: 100 });189 }));190 it('should parse a size flag', test(function() {191 nexmo = {};192 nexmo.number = sinon.createStubInstance(Number);193 client.instance.returns(nexmo);194 response.numberSearch.returns(()=>{});195 request.numberSearch('GB', { size: 25 });196 expect(nexmo.number.search).to.have.been.calledWith('GB', { features: [], size: 25 });197 }));198 it('should pass the pattern flag without a wildcard', test(function() {199 nexmo = {};200 nexmo.number = sinon.createStubInstance(Number);201 client.instance.returns(nexmo);202 response.numberSearch.returns(()=>{});203 request.numberSearch('GB', { pattern: '020'});204 expect(nexmo.number.search).to.have.been.calledWith('GB', { features: [], pattern: '020', search_pattern: 1, size: 100 });205 }));206 it('should pass the pattern flag with a start-of wildcard', test(function() {207 nexmo = {};208 nexmo.number = sinon.createStubInstance(Number);209 client.instance.returns(nexmo);210 response.numberSearch.returns(()=>{});211 request.numberSearch('GB', { pattern: '*020'});212 expect(nexmo.number.search).to.have.been.calledWith('GB', { features: [], pattern: '*020', search_pattern: 2, size: 100 });213 }));214 });215 describe('.numberBuy', () => {216 it('should call the library', test(function() {217 nexmo = {};218 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);219 client.instance.returns(nexmo);220 request.numberBuy('123', { confirm: true });221 expect(nexmo.numberInsight.get).to.have.been.calledWith({ level: 'basic', number: '123' });222 }));223 it('should handle search with a default search_pattern of 1', test(function() {224 nexmo = {};225 nexmo.number = sinon.createStubInstance(Number);226 client.instance.returns(nexmo);227 const country_code = 'GB';228 const pattern = '123';229 request.numberBuy(pattern, { country_code: country_code });230 expect(nexmo.number.search).to.have.been.calledWith(231 country_code,232 {233 features: ['VOICE'],234 pattern: pattern,235 search_pattern: 1236 }237 );238 }));239 it('should handle search with a search_pattern of 2 when * is the first pattern char', test(function() {240 nexmo = {};241 nexmo.number = sinon.createStubInstance(Number);242 client.instance.returns(nexmo);243 const country_code = 'GB';244 const pattern = '*123';245 request.numberBuy(pattern, { country_code: country_code });246 expect(nexmo.number.search).to.have.been.calledWith(247 country_code,248 {249 features: ['VOICE'],250 pattern: pattern,251 search_pattern: 2252 }253 );254 }));255 it('should handle search with a search_pattern of 0 when * is the last pattern char', test(function() {256 nexmo = {};257 nexmo.number = sinon.createStubInstance(Number);258 client.instance.returns(nexmo);259 const country_code = 'GB';260 const pattern = '123*';261 request.numberBuy(pattern, { country_code: country_code });262 expect(nexmo.number.search).to.have.been.calledWith(263 country_code,264 {265 features: ['VOICE'],266 pattern: pattern,267 search_pattern: 0268 }269 );270 }));271 it('should buy the first number only country_code flag is set', () => {272 nexmo = {};273 nexmo.number = sinon.createStubInstance(Number);274 client.instance.returns(nexmo);275 const country_code = 'GB';276 request.numberBuy(null, { country_code: country_code });277 expect(nexmo.number.search).to.have.been.calledWith(278 country_code,279 {280 features: ['VOICE']281 }282 );283 });284 });285 describe('.numberCancel', () => {286 it('should call nexmo.numberInsight.get', test(function() {287 nexmo = {};288 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);289 client.instance.returns(nexmo);290 request.numberCancel('123', { confirm: true });291 expect(nexmo.numberInsight.get).to.have.been.called;292 }));293 it('should call nexmo.number.cancel if the country code was forced', test(function() {294 nexmo = {};295 nexmo.number = sinon.createStubInstance(Number);296 nexmo.response = sinon.createStubInstance(Response);297 client.instance.returns(nexmo);298 response.numberCancel.returns(()=>{});299 request.numberCancel('123', { country_code: 'GB', confirm: true });300 expect(nexmo.number.cancel).to.have.been.called;301 }));302 });303 describe('.applicationsList', () => {304 it('should call nexmo.app.get', test(function() {305 nexmo = {};306 nexmo.app = sinon.createStubInstance(App);307 client.instance.returns(nexmo);308 response.applicationsList.returns(()=>{});309 request.applicationsList({});310 expect(nexmo.app.get).to.have.been.calledWith({page_size: 100});311 }));312 it('should parse a page flag', test(function() {313 nexmo = {};314 nexmo.app = sinon.createStubInstance(App);315 client.instance.returns(nexmo);316 response.applicationsList.returns(()=>{});317 request.applicationsList({ page: 2 });318 expect(nexmo.app.get).to.have.been.calledWith({ index: 2, page_size: 100 });319 }));320 it('should parse a size flag', test(function() {321 nexmo = {};322 nexmo.app = sinon.createStubInstance(App);323 client.instance.returns(nexmo);324 response.applicationsList.returns(()=>{});325 request.applicationsList({ size: 25 });326 expect(nexmo.app.get).to.have.been.calledWith({ page_size: 25 });327 }));328 });329 describe('.applicationCreate', () => {330 it('should call nexmo.app.create', test(function() {331 nexmo = {};332 nexmo.app = sinon.createStubInstance(App);333 client.instance.returns(nexmo);334 request.applicationCreate('name', 'answer_url', 'event_url', { type: 'voice' });335 expect(nexmo.app.create).to.have.been.called;336 }));337 it('should parse a answer_method flag', test(function() {338 nexmo = {};339 nexmo.app = sinon.createStubInstance(App);340 client.instance.returns(nexmo);341 request.applicationCreate('name', 'answer_url', 'event_url', { type: 'voice', answer_method: 'POST' });342 expect(nexmo.app.create).to.have.been.calledWith('name', 'voice', 'answer_url', 'event_url', { answer_method : 'POST' });343 }));344 it('should parse a event_method flag', test(function() {345 nexmo = {};346 nexmo.app = sinon.createStubInstance(App);347 client.instance.returns(nexmo);348 request.applicationCreate('name', 'answer_url', 'event_url', { type: 'voice', event_method: 'POST' });349 expect(nexmo.app.create).to.have.been.calledWith('name', 'voice', 'answer_url', 'event_url', { event_method : 'POST' });350 }));351 });352 describe('.applicationShow', () => {353 it('should call the library', test(function() {354 nexmo = {};355 nexmo.app = sinon.createStubInstance(App);356 client.instance.returns(nexmo);357 request.applicationShow('app_id');358 expect(nexmo.app.get).to.have.been.called;359 }));360 });361 describe('.applicationUpdate', () => {362 it('should call the library', test(function() {363 nexmo = {};364 nexmo.app = sinon.createStubInstance(App);365 client.instance.returns(nexmo);366 request.applicationUpdate('app_id', 'name', 'answer_url', 'event_url', { type: 'voice' });367 expect(nexmo.app.update).to.have.been.called;368 }));369 it('should parse a answer_method flag', test(function() {370 nexmo = {};371 nexmo = {};372 nexmo.app = sinon.createStubInstance(App);373 client.instance.returns(nexmo);374 request.applicationUpdate('app_id', 'name', 'answer_url', 'event_url', { type: 'voice', answer_method: 'POST' });375 expect(nexmo.app.update).to.have.been.calledWith('app_id', 'name', 'voice', 'answer_url', 'event_url', { answer_method : 'POST' });376 }));377 it('should parse a event_method flag', test(function() {378 nexmo = {};379 nexmo.app = sinon.createStubInstance(App);380 client.instance.returns(nexmo);381 request.applicationUpdate('app_id', 'name', 'answer_url', 'event_url', { type: 'voice', event_method: 'POST' });382 expect(nexmo.app.update).to.have.been.calledWith('app_id', 'name', 'voice', 'answer_url', 'event_url', { event_method : 'POST' });383 }));384 });385 describe('.applicationDelete', () => {386 it('should call the library', test(function() {387 nexmo = {};388 nexmo.app = sinon.createStubInstance(App);389 client.instance.returns(nexmo);390 request.applicationDelete('123', { confirm: true });391 expect(nexmo.app.delete).to.have.been.called;392 }));393 });394 describe('.applicationNumbers', () => {395 it('should call nexmo.number.get', test(function() {396 nexmo = {};397 nexmo.number = sinon.createStubInstance(Number);398 client.instance.returns(nexmo);399 response.applicationNumbers.returns(()=>{});400 request.applicationNumbers('app_id', {});401 expect(nexmo.number.get).to.have.been.called;402 }));403 it('should parse a page flag', test(function() {404 nexmo = {};405 nexmo.number = sinon.createStubInstance(Number);406 client.instance.returns(nexmo);407 response.applicationNumbers.returns(()=>{});408 request.applicationNumbers('app_id', { page: 2 });409 expect(nexmo.number.get).to.have.been.calledWith({ index: 2 });410 }));411 it('should parse a size flag', test(function() {412 nexmo = {};413 nexmo.number = sinon.createStubInstance(Number);414 client.instance.returns(nexmo);415 response.applicationNumbers.returns(()=>{});416 request.applicationNumbers('app_id', { size: 25 });417 expect(nexmo.number.get).to.have.been.calledWith({ size: 25 });418 }));419 });420 describe('.linkApp', () => {421 it('should call the nexmo.number.get({level:"basic"})', test(function() {422 nexmo = {};423 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);424 client.instance.returns(nexmo);425 request.linkApp('123', 'abc');426 expect(nexmo.numberInsight.get).to.have.been.calledWithMatch({level:'basic'});427 }));428 });429 describe('.unlinkApp', () => {430 it('should call nexmo.numberInsight.get', test(function() {431 nexmo = {};432 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);433 client.instance.returns(nexmo);434 request.unlinkApp('123');435 expect(nexmo.numberInsight.get).to.have.been.calledWithMatch({level:'basic'});436 }));437 });438 describe('.linkSms', () => {439 it('should call the library', test(function() {440 nexmo = {};441 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);442 client.instance.returns(nexmo);443 request.linkSms('123', 'abc');444 expect(nexmo.numberInsight.get).to.have.been.calledWithMatch({level:'basic'});445 }));446 });447 describe('.unlinkSms', () => {448 it('should call nexmo.numberInsight.get', test(function() {449 nexmo = {};450 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);451 client.instance.returns(nexmo);452 request.unlinkSms('123');453 expect(nexmo.numberInsight.get).to.have.been.calledWithMatch({level:'basic'});454 }));455 });456 describe('.linkTel', () => {457 it('should call nexmo.numberInsight.get', test(function() {458 nexmo = {};459 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);460 client.instance.returns(nexmo);461 request.linkTel('123', 'abc', {});462 expect(nexmo.numberInsight.get).to.have.been.calledWithMatch({level:'basic'});463 }));464 });465 describe('.unlinkTel', () => {466 it('should call nexmo.numberInsight.get', test(function() {467 nexmo = {};468 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);469 client.instance.returns(nexmo);470 request.unlinkTel('123');471 expect(nexmo.numberInsight.get).to.have.been.calledWithMatch({level:'basic'});472 }));473 describe('.linkVxml', () => {474 it('should call nexmo.numberInsight.get', test(function() {475 nexmo = {};476 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);477 client.instance.returns(nexmo);478 request.linkVxml('123', 'abc', {});479 expect(nexmo.numberInsight.get).to.have.been.calledWithMatch({level:'basic'});480 }));481 });482 describe('.unlinkVxml', () => {483 it('should call nexmo.numberInsight.get', test(function() {484 nexmo = {};485 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);486 client.instance.returns(nexmo);487 request.unlinkVxml('123');488 expect(nexmo.numberInsight.get).to.have.been.calledWithMatch({level:'basic'});489 }));490 });491 describe('.linkSip', () => {492 it('should call nexmo.numberInsight.get', test(function() {493 nexmo = {};494 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);495 client.instance.returns(nexmo);496 request.linkSip('123', 'abc', {});497 expect(nexmo.numberInsight.get).to.have.been.calledWithMatch({level:'basic'});498 }));499 });500 describe('.unlinkSip', () => {501 it('should call nexmo.numberInsight.get', test(function() {502 nexmo = {};503 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);504 client.instance.returns(nexmo);505 request.unlinkSip('123');506 expect(nexmo.numberInsight.get).to.have.been.calledWithMatch({level:'basic'});507 }));508 });509 });510 describe('.insightBasic', () => {511 it('should call nexmo.numberInsight.get', test(function() {512 nexmo = {};513 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);514 client.instance.returns(nexmo);515 request.insightBasic('4555555', { confirm: true });516 expect(nexmo.numberInsight.get).to.have.been.calledWithMatch({level:'basic'});517 }));518 });519 describe('.insightStandard', () => {520 it('should call nexmo.numberInsight.get', test(function() {521 nexmo = {};522 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);523 client.instance.returns(nexmo);524 request.insightStandard('4555555', { confirm: true });525 expect(nexmo.numberInsight.get).to.have.been.calledWithMatch({level:'standard'});526 }));527 });528 describe('.sendSms', () => {529 it('should call nexmo.message.sendSms', test(function() {530 nexmo = {};531 nexmo.message = sinon.createStubInstance(Message);532 client.instance.returns(nexmo);533 request.sendSms('to', ['Hello', 'World'], { 'from' : 'from', 'confirm' : true });534 expect(nexmo.message.sendSms).to.have.been.calledWith('from', 'to', 'Hello World');535 }));536 });537 describe('.generateJwt', () => {538 it('should call Nexmo.generateJwt', test(function() {539 var Nexmo = {540 generateJwt: sinon.spy()541 };542 client.definition.returns(Nexmo);543 request.generateJwt('path/to/private.key', [], {});544 expect(Nexmo.generateJwt).to.have.been.calledWith('path/to/private.key' );545 }));546 it('should deal with Nexmo.generateJwt with null claims', test(function() {547 var Nexmo = {548 generateJwt: sinon.spy()549 };550 client.definition.returns(Nexmo);551 request.generateJwt('path/to/private.key', [], {app_id: 'application_id'});552 expect(Nexmo.generateJwt).to.have.been.calledWith('path/to/private.key', {application_id: 'application_id'});553 }));554 it('should call Nexmo.generateJwt with additional claims', test(function() {555 var Nexmo = {556 generateJwt: sinon.spy()557 };558 client.definition.returns(Nexmo);559 request.generateJwt('path/to/private.key', ['subject=leggetter', 'jti=1475861732'], {app_id: 'application_id'});560 expect(Nexmo.generateJwt).to.have.been.calledWith('path/to/private.key', {application_id: 'application_id', subject: 'leggetter', jti: '1475861732'});561 }));562 it('should call pass generated token to response.generateJwt', test(function() {563 var Nexmo = {564 generateJwt: () => {565 return 'a token!';566 }567 };568 client.definition.returns(Nexmo);569 request.generateJwt('path/to/private.key', ['subject=leggetter', 'jti=1475861732'], {app_id: 'application_id'});570 expect(response.generateJwt).to.have.been.calledWith(null, 'a token!');571 }));572 it('should call response with an exception when singular values are provided for claims', test(function() {573 var Nexmo = {574 generateJwt: sinon.spy()575 };576 client.definition.returns(Nexmo);577 request.generateJwt('path/to/private.key', 'application_id', ['subject']);578 expect(response.generateJwt).to.have.been.calledWith(sinon.match.instanceOf(Error), null);579 }));580 it('should call response with an exception when more than one = is supplied', test(function() {581 var Nexmo = {582 generateJwt: sinon.spy()583 };584 client.definition.returns(Nexmo);585 request.generateJwt('path/to/private.key', 'application_id', ['subject=fish=monkey']);586 expect(response.generateJwt).to.have.been.calledWith(sinon.match.instanceOf(Error), null);587 }));588 });589 describe('.getCountryCode', () => {590 it('should return the country code if provided', test(function() {591 const callback = sinon.spy();592 request.getCountryCode('44555666777', { country_code: 'GB' }, callback);593 expect(callback).to.have.been.calledWith('GB');594 }));595 it('should call number insight if no country code was provided', test(function() {596 nexmo = {};597 const callback = sinon.spy();598 nexmo.numberInsight = sinon.createStubInstance(NumberInsight);599 client.instance.returns(nexmo);600 request.getCountryCode('44555666777', {}, callback);601 expect(nexmo.numberInsight.get).to.have.been.calledWith({ level: 'basic', number: '44555666777' });602 }));603 });604 });...

Full Screen

Full Screen

hud_test.js

Source:hud_test.js Github

copy

Full Screen

...27 done();28 });29 });30 setup(function() {31 this.app = sinon.createStubInstance(this.App);32 this.app.camera = sinon.createStubInstance(this.Camera);33 this.app.settings = sinon.createStubInstance(this.Settings);34 this.app.views = {35 viewfinder: sinon.createStubInstance(this.ViewfinderView),36 controls: sinon.createStubInstance(this.ControlsView),37 hud: sinon.createStubInstance(this.HudView)38 };39 // Stub 'cameras' setting40 this.app.settings.cameras = sinon.createStubInstance(this.Setting);41 this.app.settings.flashModes = sinon.createStubInstance(this.Setting);42 this.app.settings.cameras.get.withArgs('options').returns([]);43 this.app.settings.get.withArgs('cameras')44 .returns(this.app.settings.cameras);45 this.app.settings.get.withArgs('flashModes')46 .returns(this.app.settings.flashModes);47 // For convenience48 this.hud = this.app.views.hud;49 this.controls = this.app.views.controls;50 this.viewfinder = this.app.views.viewfinder;51 this.camera = this.app.camera;52 // Our test instance53 this.hudController = new this.HudController(this.app);54 });55 suite('HudController()', function() {...

Full Screen

Full Screen

camera_test.js

Source:camera_test.js Github

copy

Full Screen

...27 done();28 });29 });30 setup(function() {31 this.app = sinon.createStubInstance(this.App);32 this.app.activity = new this.Activity();33 this.app.camera = sinon.createStubInstance(this.Camera);34 this.app.views = {35 filmstrip: sinon.createStubInstance(this.View),36 viewfinder: sinon.createStubInstance(this.View)37 };38 this.app.views.filmstrip.clear = sinon.spy();39 // Settings40 this.app.settings = sinon.createStubInstance(this.Settings);41 this.app.settings.cameras = sinon.createStubInstance(this.Setting);42 this.app.settings.get43 .withArgs('cameras')44 .returns(this.app.settings.cameras);45 this.app.storage = sinon.createStubInstance(this.Storage);46 this.camera = this.app.camera;47 });48 suite('CameraController()', function() {49 setup(function() {50 sinon.stub(this.CameraController.prototype, 'teardownCamera');51 });52 teardown(function() {53 this.CameraController.prototype.teardownCamera.restore();54 });55 test('Should set the capture mode to \'camera\' by default', function() {56 this.app.settings.value.withArgs('mode').returns('picture');57 this.controller = new this.CameraController(this.app);58 assert.isTrue(this.app.camera.setMode.calledWith('picture'));59 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var MyClass = require('./myclass');4var myStub = sinon.createStubInstance(MyClass);5myStub.method1.returns(42);6assert.equal(42, myStub.method1());7var stub = sinon.stub();8stub.withArgs(100).returns(200);9stub.withArgs(300).returns(400);10assert.equal(200, stub(100));11assert.equal(400, stub(300));

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var stub = sinon.createStubInstance(OriginalConstructor);3var sinon = require('sinon');4var stub = sinon.createStubInstance(OriginalConstructor);5var sinon = require('sinon');6var stub = sinon.createStubInstance(OriginalConstructor);7var sinon = require('sinon');8var stub = sinon.createStubInstance(OriginalConstructor);9var sinon = require('sinon');10var stub = sinon.createStubInstance(OriginalConstructor);11var sinon = require('sinon');12var stub = sinon.createStubInstance(OriginalConstructor);13var sinon = require('sinon');14var stub = sinon.createStubInstance(OriginalConstructor);15var sinon = require('sinon');16var stub = sinon.createStubInstance(OriginalConstructor);17var sinon = require('sinon');18var stub = sinon.createStubInstance(OriginalConstructor);

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var MyClass = function() {4 this.method = function() {5 };6 this.property = "property";7};8var stub = sinon.createStubInstance(MyClass);9assert(stub instanceof MyClass);10assert(typeof stub.method === 'function');11assert(stub.property === undefined);12var sinon = require('sinon');13var assert = require('assert');14var MyClass = function() {15 this.method = function() {16 };17 this.property = "property";18};19var stub = sinon.createStubInstance(MyClass);20assert(stub instanceof MyClass);21assert(typeof stub.method === 'function');22assert(stub.property === undefined);23assert(stub.method() === undefined);24var sinon = require('sinon');25var assert = require('assert');26var MyClass = function() {27 this.method = function() {28 };29 this.property = "property";30};31var stub = sinon.createStubInstance(MyClass);32assert(stub instanceof MyClass);33assert(typeof stub.method === 'function');34assert(stub.property === undefined);35assert(stub.method() === undefined);36assert(stub.method() === undefined);37assert(stub.method() === undefined);38var sinon = require('sinon');39var assert = require('assert');40var MyClass = function() {41 this.method = function() {42 };43 this.property = "property";44};45var stub = sinon.createStubInstance(MyClass);46assert(stub instanceof MyClass);47assert(typeof stub.method === 'function');48assert(stub.property === undefined);49assert(stub.method() === undefined);50assert(stub.method() === undefined);51assert(stub.method() === undefined);52assert(stub.method() === undefined);53var sinon = require('sinon');54var assert = require('assert');55var MyClass = function() {56 this.method = function() {57 };58 this.property = "property";59};60var stub = sinon.createStubInstance(MyClass);61assert(stub instanceof MyClass);62assert(typeof stub.method === 'function');63assert(stub.property

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var assert = require('assert');3var obj = sinon.createStubInstance(require('./test1'));4console.log(obj);5assert(obj.method1.calledOnce);6module.exports = {7 method1: function() {8 console.log('method1 called');9 }10};11var obj = sinon.createStubInstance(require('./test1'));12var sandbox = sinon.sandbox.create();13sandbox.stub(obj, "method1");14console.log(obj);15assert(obj.method1.calledOnce);16var obj = sinon.createStubInstance(require('./test1'));17var sandbox = sinon.sandbox.create();18sandbox.stub(obj, "method1");19console.log(obj);20assert(obj.method1.calledOnce);

Full Screen

Using AI Code Generation

copy

Full Screen

1var sinon = require('sinon');2var fake = sinon.createStubInstance(MyClass);3console.log(fake.method());4var sinonChai = require('sinon-chai');5var chai = require('chai');6chai.use(sinonChai);7var fake = sinon.createStubInstance(MyClass);8console.log(fake.method());

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