这似乎很简单,但是由于某种原因我无法使其正常工作。我已经尝试了几项似乎应该可以解决但不能解决的问题。有人可以发现我在做什么错吗?
这是被测方法:
$(window).on('message', function(e) {
var $next = $('[data-myCustomAttribute]'), data = e.originalEvent.data;
if(data.payload === 'true') {
disable($next, false);
}
else {
disable($next, true);
}
});
var disable = function(elem, disabled) {
elem.prop('disabled', disabled);
};
这是我要注入的灯具:
<button data-myCustomAttribute>Next</button>
这是我的考试:
it("should enable 'next' button", function () {
window.postMessage({eventName: "MY_EVENT", payload: true}, '*');
expect(element('[data-myCustomAttribute]').isEnabled());
});
it("should disable 'next' button", function () {
window.postMessage({eventName: "MY_EVENT", payload: false}, '*');
expect(element('[data-myCustomAttribute]').not.isEnabled());
});
这不起作用,返回此错误:
TypeError: undefined is not a constructor (evaluating 'element('[data-myCustomAttribute]').isEnabled()')
以下尝试也会返回类似的错误:
it("should enable 'next' button", function () {
window.postMessage({eventName: "MY_EVENT", payload: true}, '*');
expect(element('[data-myCustomAttribute]').find("[disabled]").length().toEqual(0));
});
it("should enable 'next' button", function () {
window.postMessage({eventName: "MY_EVENT", payload: true}, '*');
expect(element('[data-myCustomAttribute]').toContain('[disabled]')).toEqual(false);
});
it("should disable 'next' button", function () {
window.postMessage({eventName: "MY_EVENT", payload: false}, '*');
expect(element('[data-myCustomAttribute]').is('[disabled]')).toEqual(true);
});
我要去哪里错了?