Best JavaScript code snippet using sinon
carouselcore.js
Source:carouselcore.js
...16 ['antie/widgets/carousel/carouselcore',17 'antie/widgets/carousel/mask'],18 function (application, CarouselCore, Mask) {19 var appendStub, appendedWidget;20 appendStub = this.sandbox.stub(CarouselCore.prototype, 'appendChildWidget');21 new CarouselCore('myCarousel');22 appendedWidget = appendStub.getCall(0).args[0];23 assertTrue('Mask added as child of carousel', appendedWidget instanceof Mask);24 }25 );26 };27 this.CarouselCoreTest.prototype.testCarouselRendersMask = function (queue) {28 queuedApplicationInit(queue,29 'lib/mockapplication',30 ['antie/widgets/carousel/carouselcore'],31 function (application, CarouselCore) {32 var carousel, renderSpy, device;33 device = application.getDevice();34 carousel = new CarouselCore('myCarousel');35 renderSpy = this.sandbox.stub(carousel._mask, 'render');36 carousel.render(device);37 assertTrue('Carousel renders mask', renderSpy.calledOnce);38 }39 );40 };41 this.CarouselCoreTest.prototype.testCarouselRenderSetsOutputElementToElementReturnedByMaskRender = function (queue) {42 queuedApplicationInit(queue,43 'lib/mockapplication',44 ['antie/widgets/carousel/carouselcore'],45 function (application, CarouselCore) {46 var carousel, device;47 device = application.getDevice();48 carousel = new CarouselCore('myCarousel');49 this.sandbox.stub(carousel._mask, 'render').returns('test');50 carousel.render(device);51 assertEquals('Carousel output element set to mask output element', 'test', carousel.outputElement);52 }53 );54 };55 this.CarouselCoreTest.prototype.testAppendAddsToWidgetStrip = function (queue) {56 queuedApplicationInit(queue,57 'lib/mockapplication',58 ['antie/widgets/carousel/carouselcore'],59 function (application, CarouselCore) {60 var carousel, appendedFromCarouselWidget;61 appendedFromCarouselWidget = {62 dummy: 'dummyWidget',63 addClass: this.sandbox.stub()64 };65 carousel = new CarouselCore('myCarousel');66 carousel._widgetStrip.append = this.sandbox.stub().withArgs(appendedFromCarouselWidget);67 carousel.append(appendedFromCarouselWidget);68 assertTrue('Carousel appends widget to WidgetStrip', carousel._widgetStrip.append.calledOnce);69 }70 );71 };72 this.CarouselCoreTest.prototype.testInsertInsertsOnWidgetStrip = function (queue) {73 queuedApplicationInit(queue,74 'lib/mockapplication',75 ['antie/widgets/carousel/carouselcore'],76 function (application, CarouselCore) {77 var carousel, insertedWidget, insertIndex;78 insertIndex = 3;79 insertedWidget = {80 dummy: 'dummyWidget',81 addClass: this.sandbox.stub()82 };83 carousel = new CarouselCore('myCarousel');84 carousel._widgetStrip.insert = this.sandbox.stub().withArgs(insertIndex, insertedWidget);85 carousel.insert(insertIndex, insertedWidget);86 assertTrue('Carousel inserts widget in WidgetStrip', carousel._widgetStrip.insert.calledOnce);87 }88 );89 };90 this.CarouselCoreTest.prototype.testRemoveRemovesFromWidgetStrip = function (queue) {91 queuedApplicationInit(queue,92 'lib/mockapplication',93 ['antie/widgets/carousel/carouselcore'],94 function (application, CarouselCore) {95 var carousel, widget, retainElement;96 retainElement = true;97 widget = {98 dummy: 'dummyWidget',99 removeClass: this.sandbox.stub()100 };101 carousel = new CarouselCore('myCarousel');102 carousel.hasChildWidget = this.sandbox.stub().returns(true);103 carousel._widgetStrip.remove = this.sandbox.stub().withArgs(widget, retainElement);104 carousel.remove(widget, retainElement);105 assertTrue('Carousel removes widget from WidgetStrip', carousel._widgetStrip.remove.calledOnce);106 }107 );108 };109 this.CarouselCoreTest.prototype.testRemoveAllRemovesAllFromWidgetStrip = function (queue) {110 queuedApplicationInit(queue,111 'lib/mockapplication',112 ['antie/widgets/carousel/carouselcore'],113 function (application, CarouselCore) {114 var carousel;115 carousel = new CarouselCore('myCarousel');116 carousel._widgetStrip.removeAll = this.sandbox.stub();117 carousel.removeAll();118 assertTrue('Carousel removes widgets from WidgetStrip', carousel._widgetStrip.removeAll.calledOnce);119 }120 );121 };122 this.CarouselCoreTest.prototype.testAppendAddsCarouselItemClassToWidget = function (queue) {123 queuedApplicationInit(queue,124 'lib/mockapplication',125 ['antie/widgets/carousel/carouselcore'],126 function (application, CarouselCore) {127 var carousel, fakeWidget;128 fakeWidget = { addClass: this.sandbox.stub() };129 carousel = new CarouselCore('myCarousel');130 carousel._widgetStrip.append = this.sandbox.stub();131 carousel.append(fakeWidget);132 assertTrue('Carousel adds carouselItem class to appended widget', fakeWidget.addClass.calledWith('carouselItem'));133 }134 );135 };136 this.CarouselCoreTest.prototype.testInsertAddsCarouselItemClassToWidget = function (queue) {137 queuedApplicationInit(queue,138 'lib/mockapplication',139 ['antie/widgets/carousel/carouselcore'],140 function (application, CarouselCore) {141 var carousel, fakeWidget;142 fakeWidget = { addClass: this.sandbox.stub() };143 carousel = new CarouselCore('myCarousel');144 carousel._widgetStrip.insert = this.sandbox.stub();145 carousel.insert(2, fakeWidget);146 assertTrue('Carousel adds carouselItem class to appended widget', fakeWidget.addClass.calledWith('carouselItem'));147 }148 );149 };150 this.CarouselCoreTest.prototype.testRemoveRemovesCarouselItemClassFromChildWidget = function (queue) {151 queuedApplicationInit(queue,152 'lib/mockapplication',153 ['antie/widgets/carousel/carouselcore'],154 function (application, CarouselCore) {155 var carousel, widget;156 widget = { removeClass: this.sandbox.stub() };157 carousel = new CarouselCore('myCarousel');158 carousel.hasChildWidget = this.sandbox.stub().returns(true);159 carousel._widgetStrip.remove = this.sandbox.stub();160 carousel.remove(widget, false);161 assertTrue('Carousel removes carouselItem class from removed widget', widget.removeClass.calledWith('carouselItem'));162 }163 );164 };165 this.CarouselCoreTest.prototype.testRemoveDoesNotRemoveCarouselItemClassFromNonChildWidget = function (queue) {166 queuedApplicationInit(queue,167 'lib/mockapplication',168 ['antie/widgets/carousel/carouselcore'],169 function (application, CarouselCore) {170 var carousel, widget;171 widget = { removeClass: this.sandbox.stub() };172 carousel = new CarouselCore('myCarousel');173 carousel.hasChildWidget = this.sandbox.stub().returns(false);174 carousel._widgetStrip.remove = this.sandbox.stub();175 carousel.remove(widget, false);176 assertFalse('Carousel does not remove carouselItem class from non child widget', widget.removeClass.calledWith('carouselItem'));177 }178 );179 };180 this.CarouselCoreTest.prototype.testItemsReturnsWidgetStripWidgets = function (queue) {181 queuedApplicationInit(queue,182 'lib/mockapplication',183 ['antie/widgets/carousel/carouselcore'],184 function (application, CarouselCore) {185 var carousel;186 carousel = new CarouselCore('myCarousel');187 carousel._widgetStrip.widgets = this.sandbox.stub().returns(['test']);188 assertEquals('Widget strip widgets returned', ['test'], carousel.items());189 }190 );191 };192 this.CarouselCoreTest.prototype.testNavigationDefaultsToBookend = function (queue) {193 queuedApplicationInit(194 queue,195 'lib/mockapplication',196 [197 'antie/widgets/carousel/carouselcore',198 'antie/widgets/button',199 'antie/widgets/carousel/navigators/bookendednavigator'200 ],201 function (application, CarouselCore, Button, BookendedNavigator) {202 var navSpy;203 navSpy = this.sandbox.spy(CarouselCore.prototype, 'setNavigator');204 new CarouselCore('myCarousel');205 assertTrue('Navigator set', navSpy.called);206 assertEquals('Navigator set to bookended', navSpy.getCall(0).args[0], BookendedNavigator);207 }208 );209 };210 this.CarouselCoreTest.prototype.testSpinAlignsIndexedWidget = function (queue) {211 queuedApplicationInit(212 queue,213 'lib/mockapplication',214 [215 'antie/widgets/carousel/carouselcore',216 'antie/widgets/carousel/mask'217 ],218 function (application, CarouselCore, Mask) {219 var carousel, maskStub, INDEX;220 INDEX = 3;221 maskStub = this.sandbox.stub(Mask.prototype, 'alignToIndex').withArgs(INDEX);222 carousel = new CarouselCore('myCarousel');223 carousel.alignToIndex(INDEX);224 assertTrue('Mask asked to align to index', maskStub.calledOnce);225 }226 );227 };228 this.CarouselCoreTest.prototype.testSpinAlignmentSet = function (queue) {229 queuedApplicationInit(230 queue,231 'lib/mockapplication',232 [233 'antie/widgets/carousel/carouselcore',234 'antie/widgets/button',235 'antie/widgets/carousel/mask'236 ],237 function (application, CarouselCore, Button, Mask) {238 var carousel, maskStub;239 var device = application.getDevice();240 this.sandbox.stub(device, 'moveElementTo');241 maskStub = this.sandbox.stub(Mask.prototype, 'setAlignPoint');242 carousel = new CarouselCore('myCarousel');243 carousel.append(new Button());244 carousel.setAlignPoint(50);245 assertTrue('Mask asked to change align point', maskStub.calledOnce);246 }247 );248 };249 this.CarouselCoreTest.prototype.testWidgetStripSetDuringInit = function (queue) {250 queuedApplicationInit(251 queue,252 'lib/mockapplication',253 [254 'antie/widgets/carousel/carouselcore',255 'antie/widgets/carousel/mask',256 'antie/widgets/carousel/strips/widgetstrip'257 ],258 function (application, CarouselCore, Mask, WidgetStrip) {259 var stripStub;260 this.sandbox.stub(Mask.prototype);261 this.sandbox.stub(WidgetStrip.prototype);262 stripStub = this.sandbox.spy(CarouselCore.prototype, 'setWidgetStrip');263 new CarouselCore('myCarousel');264 assertTrue('Widget Strip Set', stripStub.calledOnce);265 }266 );267 };268 this.CarouselCoreTest.prototype.testSetWidgetStripInitsStrip = function (queue) {269 queuedApplicationInit(270 queue,271 'lib/mockapplication',272 [273 'antie/widgets/carousel/carouselcore'274 ],275 function (application, CarouselCore) {276 var carousel, FakeStrip;277 FakeStrip = this.sandbox.spy();278 carousel = new CarouselCore('myCarousel');279 carousel._navigator.setContainer = this.sandbox.stub();280 carousel._mask.setWidgetStrip = this.sandbox.stub();281 carousel.setWidgetStrip(FakeStrip);282 assertTrue('Widget Strip Initialised', FakeStrip.calledWithNew());283 }284 );285 };286 this.CarouselCoreTest.prototype.testSetWidgetStripUpdatesNavigatorContainer = function (queue) {287 queuedApplicationInit(288 queue,289 'lib/mockapplication',290 [291 'antie/widgets/carousel/carouselcore'292 ],293 function (application, CarouselCore) {294 var carousel, FakeNav, FakeStrip;295 FakeNav = function () {};296 FakeNav.prototype = {297 init: function () {},298 setContainer: this.sandbox.stub()299 };300 FakeStrip = this.sandbox.stub();301 carousel = new CarouselCore('myCarousel');302 carousel._mask.setWidgetStrip = this.sandbox.stub();303 carousel.setNavigator(FakeNav);304 carousel.setWidgetStrip(FakeStrip);305 assertTrue('Setting widget strip updated navigator', FakeNav.prototype.setContainer.calledOnce);306 }307 );308 };309 this.CarouselCoreTest.prototype.testSetWidgetStripUpdatesMask = function (queue) {310 queuedApplicationInit(311 queue,312 'lib/mockapplication',313 [314 'antie/widgets/carousel/carouselcore',315 'antie/widgets/carousel/mask'316 ],317 function (application, CarouselCore, Mask) {318 var carousel, FakeStrip;319 this.sandbox.stub(Mask.prototype);320 FakeStrip = this.sandbox.stub();321 carousel = new CarouselCore('myCarousel');322 carousel.setWidgetStrip(FakeStrip);323 assertTrue('Setting widget strip updated mask', Mask.prototype.setWidgetStrip.calledOnce);324 }325 );326 };327 this.CarouselCoreTest.prototype.testGetActiveIndexReturnsNavigatorIndex = function (queue) {328 queuedApplicationInit(329 queue,330 'lib/mockapplication',331 [332 'antie/widgets/carousel/carouselcore',333 'antie/widgets/carousel/navigators/bookendednavigator'334 ],335 function (application, CarouselCore, BookendedNavigator) {336 var carousel, INDEX, returnedIndex;337 INDEX = 3;338 this.sandbox.stub(BookendedNavigator.prototype);339 BookendedNavigator.prototype.currentIndex.returns(INDEX);340 carousel = new CarouselCore('myCarousel');341 returnedIndex = carousel.getActiveIndex();342 assertTrue('Navigator asked for index', BookendedNavigator.prototype.currentIndex.calledOnce);343 assertEquals('getActiveIndex returns navigator index', INDEX, returnedIndex);344 }345 );346 };347 this.CarouselCoreTest.prototype.testSetActiveIndexUpdatesNavigator = function (queue) {348 queuedApplicationInit(349 queue,350 'lib/mockapplication',351 [352 'antie/widgets/carousel/carouselcore',353 'antie/widgets/carousel/navigators/bookendednavigator'354 ],355 function (application, CarouselCore, BookendedNavigator) {356 var carousel;357 this.sandbox.stub(BookendedNavigator.prototype);358 carousel = new CarouselCore('myCarousel');359 carousel.setActiveIndex(4);360 assertTrue('Navigator asked to set index', BookendedNavigator.prototype.setIndex.calledWith(4));361 }362 );363 };364 this.CarouselCoreTest.prototype.testSpinToNextAsksAlignerToMoveForwardUsingNavigator = function (queue) {365 queuedApplicationInit(366 queue,367 'lib/mockapplication',368 [369 'antie/widgets/carousel/carouselcore',370 'antie/widgets/carousel/navigators/navigator',371 'antie/widgets/carousel/aligners/aligner'372 ],373 function (application, CarouselCore, Navigator, Aligner) {374 var carousel, alignArgs;375 this.sandbox.stub(Navigator.prototype);376 this.sandbox.stub(Aligner.prototype);377 carousel = new CarouselCore('myCarousel');378 carousel.alignNext();379 assertTrue('Aligner told to move forward', Aligner.prototype.alignNext.calledOnce);380 alignArgs = Aligner.prototype.alignNext.firstCall.args;381 assertTrue('Aligner passed navigator', alignArgs[0] instanceof Navigator);382 }383 );384 };385 this.CarouselCoreTest.prototype.testSpinToPreviousAsksNavigatorToMoveBackwardUsingNavigator = function (queue) {386 queuedApplicationInit(387 queue,388 'lib/mockapplication',389 [390 'antie/widgets/carousel/carouselcore',391 'antie/widgets/carousel/navigators/navigator',392 'antie/widgets/carousel/aligners/aligner'393 ],394 function (application, CarouselCore, Navigator, Aligner) {395 var carousel, alignArgs;396 this.sandbox.stub(Navigator.prototype);397 this.sandbox.stub(Aligner.prototype);398 carousel = new CarouselCore('myCarousel');399 carousel.alignPrevious();400 assertTrue('Aligner told to move backward', Aligner.prototype.alignPrevious.calledOnce);401 alignArgs = Aligner.prototype.alignPrevious.firstCall.args;402 assertTrue('Aligner passed navigator', alignArgs[0] instanceof Navigator);403 }404 );405 };406 this.CarouselCoreTest.prototype.testDefaultOrientationIsVertical = function (queue) {407 queuedApplicationInit(408 queue,409 'lib/mockapplication',410 [411 'antie/widgets/carousel/carouselcore'412 ],413 function (application, CarouselCore) {414 var carousel;415 this.sandbox.spy(CarouselCore.prototype, '_setOrientation');416 carousel = new CarouselCore('myCarousel');417 assertEquals(carousel.orientation(), CarouselCore.orientations.VERTICAL);418 }419 );420 };421 this.CarouselCoreTest.prototype.testInitWithHorizontalOrientationSetsHorizontalOrientation = function (queue) {422 queuedApplicationInit(423 queue,424 'lib/mockapplication',425 [426 'antie/widgets/carousel/carouselcore'427 ],428 function (application, CarouselCore) {429 var carousel;430 this.sandbox.spy(CarouselCore.prototype, '_setOrientation');431 carousel = new CarouselCore('myCarousel', CarouselCore.orientations.HORIZONTAL);432 assertEquals(carousel.orientation(), CarouselCore.orientations.HORIZONTAL);433 }434 );435 };436 this.CarouselCoreTest.prototype.testOrientationPassedToMask = function (queue) {437 queuedApplicationInit(438 queue,439 'lib/mockapplication',440 [441 'antie/widgets/carousel/carouselcore',442 'antie/widgets/carousel/mask',443 'antie/widgets/carousel/orientations/vertical'444 ],445 function (application, CarouselCore, Mask, vertical) {446 this.sandbox.stub(Mask.prototype);447 new CarouselCore('myCarousel', CarouselCore.orientations.VERTICAL);448 assertEquals('Mask created with vertical orientation', vertical, Mask.prototype.init.firstCall.args[2]);449 }450 );451 };452 this.CarouselCoreTest.prototype.testOrientationPassedToWidgetStrip = function (queue) {453 queuedApplicationInit(454 queue,455 'lib/mockapplication',456 [457 'antie/widgets/carousel/carouselcore',458 'antie/widgets/carousel/strips/widgetstrip',459 'antie/widgets/carousel/orientations/horizontal'460 ],461 function (application, CarouselCore, WidgetStrip, horizontal) {462 this.sandbox.stub(WidgetStrip.prototype);463 new CarouselCore('myCarousel', CarouselCore.orientations.HORIZONTAL);464 assertEquals('Widget Strip created with vertical orientation', horizontal, WidgetStrip.prototype.init.firstCall.args[1]);465 }466 );467 };468 this.CarouselCoreTest.prototype.testBeforeAlignEventsFromStripHaveTargetResetToCarousel = function (queue) {469 queuedApplicationInit(470 queue,471 'lib/mockapplication',472 [473 'antie/widgets/carousel/carouselcore',474 'antie/widgets/carousel/strips/widgetstrip',475 'antie/widgets/carousel/orientations/horizontal',476 'antie/events/beforealignevent'477 ],478 function (application, CarouselCore, WidgetStrip, horizontal, BeforeAlignEvent) {479 var carousel;480 this.sandbox.stub(WidgetStrip.prototype);481 carousel = new CarouselCore('myCarousel', CarouselCore.orientations.HORIZONTAL);482 carousel.parentWidget = { bubbleEvent: this.sandbox.stub() };483 carousel.bubbleEvent(new BeforeAlignEvent(carousel._widgetStrip, 0));484 assertNotEquals('event target equals widget strip',485 carousel._mask, carousel.parentWidget.bubbleEvent.firstCall.args[0].target);486 assertEquals('event target changed to carousel',487 carousel, carousel.parentWidget.bubbleEvent.firstCall.args[0].target);488 }489 );490 };491 this.CarouselCoreTest.prototype.testBeforeAlignEventsNotFromWidgetStripDontHaveTargetResetToCarousel = function (queue) {492 queuedApplicationInit(493 queue,494 'lib/mockapplication',495 [496 'antie/widgets/carousel/carouselcore',497 'antie/widgets/carousel/strips/widgetstrip',498 'antie/widgets/carousel/orientations/horizontal',499 'antie/events/beforealignevent'500 ],501 function (application, CarouselCore, WidgetStrip, horizontal, BeforeAlignEvent) {502 var carousel;503 this.sandbox.stub(WidgetStrip.prototype);504 carousel = new CarouselCore('myCarousel', CarouselCore.orientations.HORIZONTAL);505 carousel.parentWidget = { bubbleEvent: this.sandbox.stub() };506 carousel.bubbleEvent(new BeforeAlignEvent('test', 0));507 assertEquals('event target unchanged',508 'test', carousel.parentWidget.bubbleEvent.firstCall.args[0].target);509 }510 );511 };512 this.CarouselCoreTest.prototype.testAfterAlignEventsFromWidgetStripHaveTargetResetToCarousel = function (queue) {513 queuedApplicationInit(514 queue,515 'lib/mockapplication',516 [517 'antie/widgets/carousel/carouselcore',518 'antie/widgets/carousel/strips/widgetstrip',519 'antie/widgets/carousel/orientations/horizontal',520 'antie/events/afteralignevent'521 ],522 function (application, CarouselCore, WidgetStrip, horizontal, AfterAlignEvent) {523 var carousel;524 this.sandbox.stub(WidgetStrip.prototype);525 carousel = new CarouselCore('myCarousel', CarouselCore.orientations.HORIZONTAL);526 carousel.parentWidget = { bubbleEvent: this.sandbox.stub() };527 carousel.bubbleEvent(new AfterAlignEvent(carousel._widgetStrip, 0));528 assertNotEquals('event target equals widget strip',529 carousel._mask, carousel.parentWidget.bubbleEvent.firstCall.args[0].target);530 assertEquals('event target changed to carousel',531 carousel, carousel.parentWidget.bubbleEvent.firstCall.args[0].target);532 }533 );534 };535 this.CarouselCoreTest.prototype.testAfterAlignEventsNotFromWidgetStripDontHaveTargetResetToCarousel = function (queue) {536 queuedApplicationInit(537 queue,538 'lib/mockapplication',539 [540 'antie/widgets/carousel/carouselcore',541 'antie/widgets/carousel/strips/widgetstrip',542 'antie/widgets/carousel/orientations/horizontal',543 'antie/events/afteralignevent'544 ],545 function (application, CarouselCore, WidgetStrip, horizontal, AfterAlignEvent) {546 var carousel;547 this.sandbox.stub(WidgetStrip.prototype);548 carousel = new CarouselCore('myCarousel', CarouselCore.orientations.HORIZONTAL);549 carousel.parentWidget = { bubbleEvent: this.sandbox.stub() };550 carousel.bubbleEvent(new AfterAlignEvent('test', 0));551 assertEquals('event target unchanged',552 'test', carousel.parentWidget.bubbleEvent.firstCall.args[0].target);553 }554 );555 };556 this.CarouselCoreTest.prototype.testNextIndexCallsNavigator = function (queue) {557 queuedApplicationInit(558 queue,559 'lib/mockapplication',560 [561 'antie/widgets/carousel/carouselcore',562 'antie/widgets/carousel/strips/widgetstrip',563 'antie/widgets/carousel/navigators/bookendednavigator'564 ],565 function (application, CarouselCore, WidgetStrip, Navigator) {566 var carousel, nextIndex;567 this.sandbox.stub(WidgetStrip.prototype);568 this.sandbox.stub(Navigator.prototype);569 nextIndex = 5;570 Navigator.prototype.nextIndex.returns(nextIndex);571 carousel = new CarouselCore('myCarousel');572 assertEquals('next index returned from navigator',573 nextIndex, carousel.nextIndex());574 }575 );576 };577 this.CarouselCoreTest.prototype.testPreviousIndexCallsNavigator = function (queue) {578 queuedApplicationInit(579 queue,580 'lib/mockapplication',581 [582 'antie/widgets/carousel/carouselcore',583 'antie/widgets/carousel/strips/widgetstrip',584 'antie/widgets/carousel/navigators/bookendednavigator'585 ],586 function (application, CarouselCore, WidgetStrip, Navigator) {587 var carousel, previousIndex;588 this.sandbox.stub(WidgetStrip.prototype);589 this.sandbox.stub(Navigator.prototype);590 previousIndex = 4;591 Navigator.prototype.previousIndex.returns(previousIndex);592 carousel = new CarouselCore('myCarousel');593 assertEquals('next index returned from navigator',594 previousIndex, carousel.previousIndex());595 }596 );597 };598 this.CarouselCoreTest.prototype.testSetActiveWidgetSetsIndexOnNavigator = function (queue) {599 queuedApplicationInit(600 queue,601 'lib/mockapplication',602 [603 'antie/widgets/carousel/carouselcore',604 'antie/widgets/carousel/strips/widgetstrip',605 'antie/widgets/carousel/mask',606 'antie/widgets/carousel/navigators/navigator',607 'antie/widgets/button'608 ],609 function (application, CarouselCore, WidgetStrip, Mask, Navigator, Button) {610 var carousel;611 this.sandbox.stub(WidgetStrip.prototype);612 this.sandbox.stub(Mask.prototype);613 this.sandbox.stub(Button.prototype);614 this.sandbox.stub(Navigator.prototype);615 carousel = new CarouselCore('myCarousel');616 assertFalse(Navigator.prototype.setIndex.called);617 carousel.setActiveWidget(new Button());618 assertTrue('setActiveWidget sets on navigator', Navigator.prototype.setIndex.called);619 }620 );621 };622 this.CarouselCoreTest.prototype.testRecalculateCallsRecalculateOnWidgetStrip = function (queue) {623 queuedApplicationInit(624 queue,625 'lib/mockapplication',626 [627 'antie/widgets/carousel/carouselcore',628 'antie/widgets/carousel/strips/widgetstrip',629 'antie/widgets/carousel/mask',630 'antie/widgets/carousel/navigators/navigator',631 'antie/widgets/button'632 ],633 function (application, CarouselCore, WidgetStrip, Mask, Navigator, Button) {634 var carousel;635 this.sandbox.stub(WidgetStrip.prototype);636 this.sandbox.stub(Mask.prototype);637 this.sandbox.stub(Button.prototype);638 this.sandbox.stub(Navigator.prototype);639 carousel = new CarouselCore('myCarousel');640 carousel.recalculate();641 assertTrue('recalculate calls recalculate on widgetstrip', WidgetStrip.prototype.recalculate.called);642 }643 );644 };645 this.CarouselCoreTest.prototype.testAutoCalculatCallsAutoCalculateOnWidgetStrip = function (queue) {646 queuedApplicationInit(647 queue,648 'lib/mockapplication',649 [650 'antie/widgets/carousel/carouselcore',651 'antie/widgets/carousel/strips/widgetstrip',652 'antie/widgets/carousel/mask',653 'antie/widgets/carousel/navigators/navigator',654 'antie/widgets/button'655 ],656 function (application, CarouselCore, WidgetStrip, Mask, Navigator, Button) {657 var carousel;658 this.sandbox.stub(WidgetStrip.prototype);659 this.sandbox.stub(Mask.prototype);660 this.sandbox.stub(Button.prototype);661 this.sandbox.stub(Navigator.prototype);662 carousel = new CarouselCore('myCarousel');663 carousel.autoCalculate('foo');664 assertTrue('autoCalculate calls autoCalculate on widgetstrip', WidgetStrip.prototype.autoCalculate.calledWith('foo'));665 }666 );667 };668 this.CarouselCoreTest.prototype.testAlignToIndexPassesOptionsToAligner = function (queue) {669 queuedApplicationInit(670 queue,671 'lib/mockapplication',672 [673 'antie/widgets/carousel/carouselcore',674 'antie/widgets/carousel/strips/widgetstrip',675 'antie/widgets/carousel/mask',676 'antie/widgets/carousel/navigators/navigator',677 'antie/widgets/button',678 'antie/widgets/carousel/aligners/aligner'679 ],680 function (application, CarouselCore, WidgetStrip, Mask, Navigator, Button, Aligner) {681 var carousel, options;682 this.sandbox.stub(WidgetStrip.prototype);683 this.sandbox.stub(Mask.prototype);684 this.sandbox.stub(Button.prototype);685 this.sandbox.stub(Navigator.prototype);686 this.sandbox.stub(Aligner.prototype);687 options = {test: 'test'};688 carousel = new CarouselCore('myCarousel');689 carousel.alignToIndex(3, options);690 assertTrue('options passed to aligner', Aligner.prototype.alignToIndex.calledWith(3, options));691 }692 );693 };694 this.CarouselCoreTest.prototype.testAlignNextPassesOptionsToAligner = function (queue) {695 queuedApplicationInit(696 queue,697 'lib/mockapplication',698 [699 'antie/widgets/carousel/carouselcore',700 'antie/widgets/carousel/strips/widgetstrip',701 'antie/widgets/carousel/mask',702 'antie/widgets/carousel/navigators/navigator',703 'antie/widgets/button',704 'antie/widgets/carousel/aligners/aligner'705 ],706 function (application, CarouselCore, WidgetStrip, Mask, Navigator, Button, Aligner) {707 var carousel, options;708 this.sandbox.stub(WidgetStrip.prototype);709 this.sandbox.stub(Mask.prototype);710 this.sandbox.stub(Button.prototype);711 this.sandbox.stub(Navigator.prototype);712 this.sandbox.stub(Aligner.prototype);713 options = {test: 'test'};714 carousel = new CarouselCore('myCarousel');715 carousel.alignNext(options);716 assertEquals('options passed to aligner', options, Aligner.prototype.alignNext.firstCall.args[1]);717 }718 );719 };720 this.CarouselCoreTest.prototype.testAlignPreviousPassesOptionsToAligner = function (queue) {721 queuedApplicationInit(722 queue,723 'lib/mockapplication',724 [725 'antie/widgets/carousel/carouselcore',726 'antie/widgets/carousel/strips/widgetstrip',727 'antie/widgets/carousel/mask',728 'antie/widgets/carousel/navigators/navigator',729 'antie/widgets/button',730 'antie/widgets/carousel/aligners/aligner'731 ],732 function (application, CarouselCore, WidgetStrip, Mask, Navigator, Button, Aligner) {733 var carousel, options;734 this.sandbox.stub(WidgetStrip.prototype);735 this.sandbox.stub(Mask.prototype);736 this.sandbox.stub(Button.prototype);737 this.sandbox.stub(Navigator.prototype);738 this.sandbox.stub(Aligner.prototype);739 options = {test: 'test'};740 carousel = new CarouselCore('myCarousel');741 carousel.alignPrevious(options);742 assertEquals('options passed to aligner', options, Aligner.prototype.alignPrevious.firstCall.args[1]);743 }744 );745 };746 this.CarouselCoreTest.prototype.testCompleteAlignmentDelegatesToAligner = function (queue) {747 queuedApplicationInit(748 queue,749 'lib/mockapplication',750 [751 'antie/widgets/carousel/carouselcore',752 'antie/widgets/carousel/strips/widgetstrip',753 'antie/widgets/carousel/mask',754 'antie/widgets/carousel/navigators/navigator',755 'antie/widgets/button',756 'antie/widgets/carousel/aligners/aligner'757 ],758 function (application, CarouselCore, WidgetStrip, Mask, Navigator, Button, Aligner) {759 var carousel;760 this.sandbox.stub(WidgetStrip.prototype);761 this.sandbox.stub(Mask.prototype);762 this.sandbox.stub(Button.prototype);763 this.sandbox.stub(Navigator.prototype);764 this.sandbox.stub(Aligner.prototype);765 carousel = new CarouselCore('myCarousel');766 carousel.alignPrevious();767 carousel.completeAlignment();768 assertTrue('Complete delegated to aligner', Aligner.prototype.complete.calledOnce);769 }770 );771 };772 this.CarouselCoreTest.prototype.testSetNormalisedAlignPointDelegatesToMask = function (queue) {773 queuedApplicationInit(774 queue,775 'lib/mockapplication',776 [777 'antie/widgets/carousel/carouselcore',778 'antie/widgets/carousel/strips/widgetstrip',779 'antie/widgets/carousel/mask',780 'antie/widgets/carousel/navigators/navigator',781 'antie/widgets/button',782 'antie/widgets/carousel/aligners/aligner'783 ],784 function (application, CarouselCore, WidgetStrip, Mask, Navigator, Button, Aligner) {785 var carousel;786 this.sandbox.stub(WidgetStrip.prototype);787 this.sandbox.stub(Mask.prototype);788 this.sandbox.stub(Button.prototype);789 this.sandbox.stub(Navigator.prototype);790 this.sandbox.stub(Aligner.prototype);791 carousel = new CarouselCore('myCarousel');792 carousel.setNormalisedAlignPoint(0.8);793 assertTrue('setNormalisedAlignPoint delegated to mask', Mask.prototype.setNormalisedAlignPoint.calledOnce);794 }795 );796 };797 this.CarouselCoreTest.prototype.testSetNormalisedWidgetAlignPointDelegatesToMask = function (queue) {798 queuedApplicationInit(799 queue,800 'lib/mockapplication',801 [802 'antie/widgets/carousel/carouselcore',803 'antie/widgets/carousel/strips/widgetstrip',804 'antie/widgets/carousel/mask',805 'antie/widgets/carousel/navigators/navigator',806 'antie/widgets/button',807 'antie/widgets/carousel/aligners/aligner'808 ],809 function (application, CarouselCore, WidgetStrip, Mask, Navigator, Button, Aligner) {810 var carousel;811 this.sandbox.stub(WidgetStrip.prototype);812 this.sandbox.stub(Mask.prototype);813 this.sandbox.stub(Button.prototype);814 this.sandbox.stub(Navigator.prototype);815 this.sandbox.stub(Aligner.prototype);816 carousel = new CarouselCore('myCarousel');817 carousel.setNormalisedWidgetAlignPoint(0.8);818 assertTrue('setNormalisedWidgetAlignPoint delegated to mask', Mask.prototype.setNormalisedWidgetAlignPoint.calledOnce);819 }820 );821 };822 this.CarouselCoreTest.prototype.testSetWidgetLengthsDelegatesToStrip = function (queue) {823 queuedApplicationInit(824 queue,825 'lib/mockapplication',826 [827 'antie/widgets/carousel/carouselcore',828 'antie/widgets/carousel/strips/widgetstrip',829 'antie/widgets/carousel/mask',830 'antie/widgets/carousel/navigators/navigator',831 'antie/widgets/button',832 'antie/widgets/carousel/aligners/aligner'833 ],834 function (application, CarouselCore, WidgetStrip, Mask, Navigator, Button, Aligner) {835 var carousel;836 this.sandbox.stub(WidgetStrip.prototype);837 this.sandbox.stub(Mask.prototype);838 this.sandbox.stub(Button.prototype);839 this.sandbox.stub(Navigator.prototype);840 this.sandbox.stub(Aligner.prototype);841 carousel = new CarouselCore('myCarousel');842 carousel.setWidgetLengths(50);843 assertTrue('setLength delegated to strip', WidgetStrip.prototype.setLengths.calledOnce);844 }845 );846 };847 this.CarouselCoreTest.prototype.testSetWidgetLengthsDelegatesToMask = function (queue) {848 queuedApplicationInit(849 queue,850 'lib/mockapplication',851 [852 'antie/widgets/carousel/carouselcore',853 'antie/widgets/carousel/strips/widgetstrip',854 'antie/widgets/carousel/mask',855 'antie/widgets/carousel/navigators/navigator',856 'antie/widgets/button',857 'antie/widgets/carousel/aligners/aligner'858 ],859 function (application, CarouselCore, WidgetStrip, Mask, Navigator, Button, Aligner) {860 var carousel;861 this.sandbox.stub(WidgetStrip.prototype);862 this.sandbox.stub(Mask.prototype);863 this.sandbox.stub(Button.prototype);864 this.sandbox.stub(Navigator.prototype);865 this.sandbox.stub(Aligner.prototype);866 carousel = new CarouselCore('myCarousel');867 carousel.setMaskLength(27);868 assertTrue('setMaskLength delegated to mask', Mask.prototype.setLength.calledOnce);869 assertEquals('setMaskLength passes value through', 27, Mask.prototype.setLength.getCall(0).args[0]);870 }871 );872 };...
Using AI Code Generation
1var sinon = require('sinon');2var chai = require('chai');3var expect = chai.expect;4var assert = chai.assert;5var should = chai.should();6var sinonChai = require("sinon-chai");7chai.use(sinonChai);8var myObj = {9 myMethod: function(){10 return 1;11 }12};13describe('test', function(){14 it('should stub myMethod', function(){15 var stub = sinon.stub(myObj, 'myMethod');16 stub.returns(2);17 expect(myObj.myMethod()).to.equal(2);18 });19});
Using AI Code Generation
1describe('some test', function() {2 var sandbox;3 beforeEach(function() {4 sandbox = sinon.sandbox.create();5 });6 afterEach(function() {7 sandbox.restore();8 });9 it('should do something', function() {10 var stub = sandbox.stub(someObject, 'someMethod');11 stub.returns('some value');12 expect(someObject.someMethod()).to.be('some value');13 });14});15describe('some test', function() {16 var sandbox;17 beforeEach(function() {18 sandbox = sinon.sandbox.create();19 });20 afterEach(function() {21 sandbox.restore();22 });23 it('should do something', function() {24 var spy = sandbox.spy(someObject, 'someMethod');25 someObject.someMethod();26 expect(spy.calledOnce).to.be(true);27 });28});29describe('some test', function() {30 var sandbox;31 beforeEach(function() {32 sandbox = sinon.sandbox.create();33 });34 afterEach(function() {35 sandbox.restore();36 });37 it('should do something', function() {38 var mock = sandbox.mock(someObject);39 mock.expects('someMethod').once();40 someObject.someMethod();41 mock.verify();42 });43});44describe('some test', function() {45 var sandbox;46 beforeEach(function() {47 sandbox = sinon.sandbox.create();48 });49 afterEach(function() {50 sandbox.restore();51 });52 it('should do something', function() {53 this.server.respondWith(function(request) {54 request.respond(200, {}, 'some response');55 });56 someObject.someMethod();57 this.server.respond();58 });59});60describe('some test', function() {61 var sandbox;62 beforeEach(function() {63 sandbox = sinon.sandbox.create();64 });65 afterEach(function() {66 sandbox.restore();67 });68 it('should do something', function() {69 this.server.respondWith(function(request) {70 request.respond(200, {}, 'some response');71 });72 someObject.someMethod();73 this.server.respond();74 });75});
Using AI Code Generation
1var sinon = require('sinon');2var assert = require('assert');3var sandbox = sinon.sandbox.create();4var obj = {5 method: function () {6 return 1;7 }8};9sandbox.stub(obj, 'method').returns(2);10assert.equal(obj.method(), 2);11sandbox.restore();12var sinon = require('sinon');13var assert = require('assert');14var sandbox = sinon.sandbox.create();15var obj = {16 method: function () {17 return 1;18 }19};20sandbox.stub(obj, 'method').returns(2);21assert.equal(obj.method(), 2);22sandbox.restore();23var sinon = require('sinon');24var assert = require('assert');25var sandbox = sinon.sandbox.create();26var obj = {27 method: function () {28 return 1;29 }30};31sandbox.spy(obj, 'method');32obj.method();33assert(obj.method.called);34sandbox.restore();35var sinon = require('sinon');36var assert = require('assert');37var sandbox = sinon.sandbox.create();38var obj = {39 method: function () {40 return 1;41 }42};43sandbox.spy(obj, 'method');44obj.method();45assert(obj.method.called);46sandbox.restore();47var sinon = require('sinon');48var assert = require('assert');49var sandbox = sinon.sandbox.create();50var obj = {51 method: function () {52 return 1;53 }54};55var mock = sandbox.mock(obj);56mock.expects('method').once().returns(2);57assert.equal(obj.method(), 2);58mock.verify();59sandbox.restore();60var sinon = require('sinon');61var assert = require('assert');62var sandbox = sinon.sandbox.create();63var obj = {64 method: function () {65 return 1;66 }67};68var mock = sandbox.mock(obj);69mock.expects('method').once().returns(2);70assert.equal(obj.method(), 2);71mock.verify();
Using AI Code Generation
1var sinon = require('sinon');2var assert = require('assert');3var obj = { foo: function() { return 1; } };4var stub = sinon.stub(obj, 'foo').returns(2);5stub.restore();6var sinon = require('sinon');7var assert = require('assert');8var obj = { foo: function() { return 1; } };9var stub = sinon.stub(obj, 'foo').returns(2);10stub.restore();11var sinon = require('sinon');12var assert = require('assert');13var obj = { foo: function() { return 1; } };14var stub = sinon.stub(obj, 'foo').returns(2);15stub.restore();
Using AI Code Generation
1var sinon = require('sinon');2var obj = {3 method: function () {}4};5var stub = sinon.stub(obj, "method");6var chai = require('chai');7var sinonChai = require('sinon-chai');8chai.use(sinonChai);9var obj = {10 method: function () {}11};12var stub = chai.spy.on(obj, "method");13var chai = require('chai');14var sinonChai = require('sinon-chai');15chai.use(sinonChai);16var obj = {17 method: function () {}18};19var stub = sinon.stub(obj, "method");20chai.spy.on(obj, "method");21var chai = require('chai');22var sinonChai = require('sinon-chai');23chai.use(sinonChai);24var obj = {25 method: function () {}26};27var stub = sinon.stub(obj, "method");28chai.spy.on(obj, "method");29var chai = require('chai');30var sinonChai = require('sinon-chai');31chai.use(sinonChai);32var obj = {33 method: function () {}34};35var stub = sinon.stub(obj, "method");36chai.spy.on(obj, "method");37var chai = require('chai');38var sinonChai = require('sinon-chai');39chai.use(sinonChai);40var obj = {41 method: function () {}42};43var stub = sinon.stub(obj, "method");44chai.spy.on(obj, "method");45var chai = require('chai');46var sinonChai = require('sinon-chai');47chai.use(sinonChai);48var obj = {49 method: function () {}50};51var stub = sinon.stub(obj, "method");52chai.spy.on(obj, "method");53var chai = require('chai');54var sinonChai = require('sinon-chai');55chai.use(sinonChai);56var obj = {57 method: function () {}58};59var stub = sinon.stub(obj, "method");
Using AI Code Generation
1var sinon = require('sinon');2var chai = require('chai');3var expect = chai.expect;4describe('test', function () {5 it('should stub method', function () {6 var obj = {7 method: function () {8 return 'real';9 }10 };11 var stub = sinon.stub(obj, 'method').returns('fake');12 expect(obj.method()).to.equal('fake');13 stub.restore();14 expect(obj.method()).to.equal('real');15 });16});
Using AI Code Generation
1var sinon = require('sinon');2var chai = require('chai');3var expect = chai.expect;4var assert = chai.assert;5var should = chai.should();6describe('Stubbing', function() {7 it('should stub a method', function() {8 var obj = {9 method: function() {10 console.log('original method');11 }12 };13 var stub = sinon.stub(obj, 'method');14 obj.method();15 stub.called.should.be.true;16 });17});18var sinon = require('sinon');19var chai = require('chai');20var expect = chai.expect;21var assert = chai.assert;22var should = chai.should();23describe('Stubbing', function() {24 it('should stub a method with return value', function() {25 var obj = {26 method: function() {27 console.log('original method');28 }29 };30 var stub = sinon.stub(obj, 'method').returns('stubbed method');31 obj.method().should.equal('stubbed method');32 });33});34var sinon = require('sinon');35var chai = require('chai');36var expect = chai.expect;37var assert = chai.assert;38var should = chai.should();39describe('Stubbing', function() {40 it('should stub a method with callback', function() {41 var obj = {42 method: function() {43 console.log('original method');44 }45 };46 var stub = sinon.stub(obj, 'method', function(callback) {47 callback('callback called');48 });49 obj.method(function(result) {50 result.should.equal('callback called');51 });52 });53});54var sinon = require('sinon');55var chai = require('chai');56var expect = chai.expect;57var assert = chai.assert;58var should = chai.should();
Using AI Code Generation
1var sandbox = sinon.sandbox.create();2var stub = sandbox.stub();3stub.returns(42);4stub();5var stub = this.sandbox.stub();6stub.returns(42);7stub();8var sandbox = sinon.sandbox.create();9var stub = sandbox.stub();10stub.returns(42);11stub();12var stub = this.sandbox.stub();13stub.returns(42);14stub();15var sandbox = sinon.sandbox.create();16var stub = sandbox.stub();17stub.returns(42);18stub();19var stub = this.sandbox.stub();20stub.returns(42);21stub();22var sandbox = sinon.sandbox.create();23var stub = sandbox.stub();24stub.returns(42);25stub();26var stub = this.sandbox.stub();27stub.returns(42);28stub();29var sandbox = sinon.sandbox.create();30var stub = sandbox.stub();31stub.returns(42);32stub();33var stub = this.sandbox.stub();34stub.returns(42);35stub();36var sandbox = sinon.sandbox.create();37var stub = sandbox.stub();38stub.returns(42);39stub();
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!