I have a small angular app that displays lightboxes. I didn't find anything appropriate (look good on mobile) made for angular, so I settled on magnific-popup. Magnific popup uses jquery to initialize popups:
$(document).ready ->
$('.image-link').magnificPopup({type:'image'})
I have written a minimal directive which I use to get this working with angular:
angular.module('myapp').directive 'magnificHelper', ($timeout) ->
restrict: 'A'
link: (scope, element, attr) ->
if (scope.$last == true)
$timeout ->
element.parent().find('.image-link').magnificPopup
type:'image'
gallery: {enabled: true}
This works well, but I am unsure how to write a unit test for this code. I have tried to find an answer online and I guess this must be a fairly common problem, but I didn't find any relevant solutions.
It depends on what you want to test, a basic test could check if
$last
is defined, e.g.:I guess that you can also do something like
$scope.magnificPopup = element.parent().find('.image-link').magnificPopup
and then inside your test check the$scope.magnificPopup
value