Skip to content
This repository was archived by the owner on Dec 30, 2018. It is now read-only.

Commit bf280d0

Browse files
committed
fix(test): make reload-on-resize tests more specific
1 parent 6065e18 commit bf280d0

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

src/angular-masonry.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,11 @@
131131
columnWidth: parseInt(attrs.columnWidth, 10) || attrs.columnWidth
132132
}, attrOptions || {});
133133
element.masonry(options);
134+
scope.masonryContainer = element[0];
134135
var loadImages = scope.$eval(attrs.loadImages);
135136
ctrl.loadImages = loadImages !== false;
136137
var preserveOrder = scope.$eval(attrs.preserveOrder);
137-
ctrl.preserveOrder = (preserveOrder !== false && attrs.preserveOrder !== undefined);
138+
ctrl.preserveOrder = (preserveOrder !== false && attrs.preserveOrder !== undefined);
138139
var reloadOnShow = scope.$eval(attrs.reloadOnShow);
139140
if (reloadOnShow !== false && attrs.reloadOnShow !== undefined) {
140141
scope.$watch(function () {
@@ -147,9 +148,7 @@
147148
}
148149
var reloadOnResize = scope.$eval(attrs.reloadOnResize);
149150
if (reloadOnResize !== false && attrs.reloadOnResize !== undefined) {
150-
scope.$watch(function () {
151-
return element.prop('offsetWidth');
152-
}, function (newWidth, oldWidth) {
151+
scope.$watch('masonryContainer.offsetWidth', function (newWidth, oldWidth) {
153152
if (newWidth != oldWidth) {
154153
ctrl.reload();
155154
}

test/spec/directive.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ describe 'angular-masonry', ->
8282
element = angular.element '<masonry reload-on-resize></masonry>'
8383
element = $compile(element)(@scope)
8484

85-
expect(@scope.$watch).toHaveBeenCalled()
85+
expect(@scope.$watch).toHaveBeenCalledWith('masonryContainer.offsetWidth', sinon.match.func );
8686
)
8787

8888
it 'should not setup a $watch when the reload-on-resize is missing', inject(($compile) =>
8989
sinon.spy(@scope, '$watch')
9090
element = angular.element '<masonry></masonry>'
9191
element = $compile(element)(@scope)
9292

93-
expect(@scope.$watch).not.toHaveBeenCalled()
93+
expect(@scope.$watch).not.toHaveBeenCalledWith('masonryContainer.offsetWidth', sinon.match.func );
9494
)
9595

9696
describe 'MasonryCtrl', =>

0 commit comments

Comments
 (0)