jstd = jstestdriver; dump = bind(jstd.console, jstd.console.log); beforeEach(function(){ this.addMatchers({ toBeInvalid: function(){ var element = jqLite(this.actual); var hasClass = element.hasClass('ng-validation-error'); var validationError = element.attr('ng-validation-error'); this.message = function(){ if (!hasClass) return "Expected class 'ng-validation-error' not found."; return "Expected an error message, but none was found."; }; return hasClass && validationError; }, toBeValid: function(){ var element = jqLite(this.actual); var hasClass = element.hasClass('ng-validation-error'); this.message = function(){ return "Expected to not have class 'ng-validation-error' but found."; }; return !hasClass; }, toEqualData: function(expected) { return equals(this.actual, expected); }, toHaveClass: function(clazz) { this.message = function(){ return "Expected '" + sortedHtml(this.actual) + "' to have class '" + clazz + "'."; }; return this.actual.hasClass ? this.actual.hasClass(clazz) : jqLite(this.actual).hasClass(clazz); } }); }); function nakedExpect(obj) { return expect(angular.fromJson(angular.toJson(obj))); } function childNode(element, index) { return jqLite(element[0].childNodes[index]); } extend(angular, { 'element': jqLite, 'compile': compile, 'scope': createScope, 'copy': copy, 'extend': extend, 'equals': equals, 'foreach': foreach, 'noop':noop, 'bind':bind, 'toJson': toJson, 'fromJson': fromJson, 'identity':identity, 'isUndefined': isUndefined, 'isDefined': isDefined, 'isString': isString, 'isFunction': isFunction, 'isObject': isObject, 'isNumber': isNumber, 'isArray': isArray }); function sortedHtml(element) { var html = ""; foreach(jqLite(element), function toString(node) { if (node.nodeName == "#text") { html += escapeHtml(node.nodeValue); } else { html += '<' + node.nodeName.toLowerCase(); var attributes = node.attributes || []; var attrs = []; if (node.className) attrs.push(' class="' + node.className + '"'); for(var i=0; i'; } }); return html; } function isCssVisible(node) { var display = node.css('display'); if (display == 'block') display = ""; return display != 'none'; } function assertHidden(node) { assertFalse("Node should be hidden but vas visible: " + sortedHtml(node), isCssVisible(node)); } function assertVisible(node) { assertTrue("Node should be visible but vas hidden: " + sortedHtml(node), isCssVisible(node)); } function assertJsonEquals(expected, actual) { assertEquals(toJson(expected), toJson(actual)); } function assertUndefined(value) { assertEquals('undefined', typeof value); } function assertDefined(value) { assertTrue(toJson(value), !!value); } function assertThrows(error, fn){ var exception = null; try { fn(); } catch(e) { exception = e; } if (!exception) { fail("Expecting exception, none thrown"); } assertEquals(error, exception); } log = noop; error = noop; function click(element) { element = jqLite(element); var type = lowercase(element.attr('type')); var name = lowercase(nodeName(element)); if (msie) { if (name == 'input') { if (type == 'radio' || type == 'checkbox') { element[0].checked = ! element[0].checked; } } } if (name == 'option') { element.parent().val(element.val()); JQLite.prototype.trigger.call(element.parent(), 'change'); } else { JQLite.prototype.trigger.call(element, 'click'); } } function rethrow(e) { if(e) { throw e; } }