2
0
Эх сурвалжийг харах

some additional automated test utilities

Adam Shaw 11 жил өмнө
parent
commit
b985235098

+ 1 - 0
build/karma.conf.js

@@ -22,6 +22,7 @@ module.exports = function(config) {
 
 			'../lib/moment/moment.js',
 			'../lib/jquery/dist/jquery.js',
+			'../lib/jquery-ui/jquery-ui.js',
 
 			// for jquery simulate
 			'../lib/jquery-simulate-ext/libs/bililiteRange.js',

+ 38 - 1
tests/lib/jasmine-ext.js

@@ -65,7 +65,8 @@ beforeEach(function() {
 					var outer = getBounds(expected);
 					var inner = getBounds(actual);
 					var result = {
-						pass: inner.left >= outer.left &&
+						pass: outer && inner &&
+							inner.left >= outer.left &&
 							inner.right <= outer.right &&
 							inner.top >= outer.top &&
 							inner.bottom <= outer.bottom
@@ -76,6 +77,38 @@ beforeEach(function() {
 					return result;
 				}
 			};
+		},
+		toBeLeftOf: function() {
+			return {
+				compare: function(actual, expected) {
+					var subjectBounds = getBounds(actual);
+					var otherBounds = getBounds(expected);
+					var result = {
+						pass: subjectBounds && otherBounds &&
+							subjectBounds.right <= otherBounds.left
+					};
+					if (!result.pass) {
+						result.message = 'Element is not to the left of the other element';
+					}
+					return result;
+				}
+			};
+		},
+		toBeRightOf: function() {
+			return {
+				compare: function(actual, expected) {
+					var subjectBounds = getBounds(actual);
+					var otherBounds = getBounds(expected);
+					var result = {
+						pass: subjectBounds && otherBounds &&
+							subjectBounds.left >= otherBounds.right
+					};
+					if (!result.pass) {
+						result.message = 'Element is not to the right of the other element';
+					}
+					return result;
+				}
+			};
 		}
 
 	});
@@ -97,6 +130,10 @@ beforeEach(function() {
 		var el = $(node);
 		var offset = el.offset();
 
+		if (!offset) {
+			return false;
+		}
+
 		return {
 			top: offset.top,
 			left: offset.left,