我正在尝试测试是否在茉莉花中正确禁用了某个字段,但我遇到了一个奇怪的错误:
https://gist.github.com/3366765
Error: Expected { 0 : HTMLNode, length : 1, context : HTMLNode, selector : '#input1', constructor : Function, init : Function, jquery : '1.7.2', size : Function, toArray : Function, get : Function, pushStack : Function, each : Function, ready : Function, eq : Function, first : Function, last : Function, slice : Function, map : Function, end : Function, push : Function, sort : Function, splice : Function, extend : Function, data : Function, removeData : Function, queue : Function, dequeue : Function, delay : Function, clearQueue : Function, promise : Function, attr : Function, removeAttr : Function, prop : Function, removeProp : Function, addClass : Function, removeClass : Function, toggleClass : Function, hasClass : Function, val : Function, on : Function, one : Function, off : Function, bind : Function, unbind : Function, live : Function, die : Function, delegate : Function, undelegate : Function, trigger : Function, triggerHandler : Function, toggle : Function, hover : Function, blur : Function, focus : Function, focusin : Function, focusout : Function, load : Function, resize : Function, scroll : Function, unload : Function, click : Function, dblclick : Function, mousedown : Function, mouseup : Function, mousemove : Function, mouseover : Function, mouseout : Function, mouseenter : Function, mouseleave : Function, change : Function, select : Function, submit : Function, keydown : Function, keypress : Function, keyup : Function, error : Function, contextmenu : Function, find : Function, has : Function, not : Function, filter : Function, is : Function, closest : Function, index : Function, add : Function, andSelf : Function, parent : Function, parents : Function, parentsUntil : Function, next : Function, prev : Function, nextAll : Function, prevAll : Function, nextUntil : Function, prevUntil : Function, siblings : Function, children : Function, contents : Function, text : Function, wrapAll : Function, wrapInner : Function, wrap : Function, unwrap : Function, append : Function, prepend : Function, before : Function, after : Function, remove : Function, empty : Function, clone : Function, html : Function, replaceWith : Function, detach : Function, domManip : Function, appendTo : Function, prependTo : Function, insertBefore : Function, insertAfter : Function, replaceAll : Function, css : Function, serialize : Function, serializeArray : Function, ajaxStart : Function, ajaxStop : Function, ajaxComplete : Function, ajaxError : Function, ajaxSuccess : Function, ajaxSend : Function, show : Function, hide : Function, _toggle : Function, fadeTo : Function, animate : Function, stop : Function, slideDown : Function, slideUp : Function, slideToggle : Function, fadeIn : Function, fadeOut : Function, fadeToggle : Function, offset : Function, position : Function, offsetParent : Function, scrollLeft : Function, scrollTop : Function, innerHeight : Function, outerHeight : Function, height : Function, innerWidth : Function, outerWidth : Function, width : Function, propAttr : Function, _focus : Function, scrollParent : Function, zIndex : Function, disableSelection : Function, enableSelection : Function, mouse : Function, draggable : Function, droppable : Function, resizable : Function, selectable : Function, sortable : Function, _addClass : Function, _removeClass : Function, _toggleClass : Function, switchClass : Function, effect : Function, _show : Function, _hide : Function, __toggle : Function, cssUnit : Function, accordion : Function, autocomplete : Function, menu : Function, button : Function, buttonset : Function, datepicker : Function, dialog : Function, progressbar : Function, slider : Function, tabs : Function, alert : Function, carousel : Function, collapse : Function, dropdown : Function, modal : Function, scrollspy : Function, tab : Function, tooltip : Function, popover : Function, typeahead : Function } to be true.
at new jasmine.ExpectationResult (http://localhost:8888/__JASMINE_ROOT__/jasmine.js:102:32)
describe("disableFields", function() {
var $trigger, $input1, $input2, $otherInput;
var fixture = "<input id='input1' class='disable'></input>" +
"<input id='otherInput' class='other'></input>" +
"<button id='submit' data-behavior='disableFields' data-selector='.disable' data-form-id='form'></input>";
beforeEach(function() {
$('#jasmine_content').empty();
$('#jasmine_content').append(fixture);
Elemental.load(document);
});
it('disables all the inputs', function() {
$trigger = $('#submit');
expect($("#input1").prop("disabled", false)).toBe(true);
$trigger.click();
expect($("#input1").prop("disabled", true)).toBe(true);
});
});
我不确定为什么茉莉花会在选择器上抛出错误,有没有人有任何想法?
- 由于
答案 0 :(得分:1)
你遗漏了两件事,
expect($("#input1"),prop("disabeld", false)).toBe(true);
disabeld
应为disabled
和
$("#input1"),prop("disabeld"..
您必须使用dot
代替comma
。
但在这两种情况下,
expect($("#input1").prop("disabled", true)).toBe(true);
将永远不会被评估为true
,因为$("#input1").prop("disabled", true)
返回JQuery对象而不是bool值。所以使用
expect($("#input1").prop("disabled")).toBe(true);
代替。
答案 1 :(得分:0)
我不确定,但你有错字:
expect($("#input1"),prop("disabeld", false)).toBe(true);
“禁用”应该被“禁用”。