Thanks John, I'll give that a try. Raul
On Mar 27, 2014, at 8:28 AM, John Walker <[email protected]> wrote: > Try appending the element to the body. When i did a `dump` of a directives > width without appending it i got 0px, after i got a width. Hopefully that > will work for you, my test is is coffeescript. > > describe 'focus directive', -> > > beforeEach module 'jw.focus' > > $compile = null > scope = null > $timeout = null > element = null > > beforeEach inject (_$timeout_, _$compile_, $rootScope) -> > $timeout = _$timeout_ > $compile = _$compile_ > scope = $rootScope > > element = angular.element('<input jw-focus class="form-control" > />') > element.appendTo(document.body) > $compile(element)(scope) > scope.$digest() > > > > it 'should be focused on page load', -> > $timeout.flush() > dump element.css('width') > expect(element).toBeFocused() > > > > On Wednesday, March 26, 2014 4:22:29 PM UTC-6, Raul Vieira wrote: > Hi there, > > I have a directive which will change it's width based on it's parent's size. > I'd like to unit test this, but it looks like the parent element doesn't have > a width in my unit test. Notes: phantomjs, jquery, ng 1.2.13. > > Below is the method invoked from the directive's template: > > scope.adjustBar = function(barName, delta) { > > var bar = elem.find('.' + barName + ' .progress-bar'), > width = bar.width(), > parentWidth = bar.parent('.progress').width(); > > console.log('Parent width is: ' + parentWidth); > > bar.css('width', (((width += delta) / parentWidth) * 100) + '%'); > > }; > > Below is the HTML: > > <div class="a-parent"> > <button class="btn decrease" > data-ng-click="adjustBar('a-parent', -10)">Decrease</button> > <div class="progress"> > <div class="progress-bar progress-bar-success" > role="progressbar" > aria-valuenow="50" > aria-valuemin="0" > aria-valuemax="100"> > <span class="sr-only">50% Complete</span> > </div> > </div> > <button class="btn increase" > data-ng-click="adjustBar('a-parent', 10)">Increase</button> > </div> > > What do you think? > > Raul > > -- > You received this message because you are subscribed to the Google Groups > "AngularJS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
