如何才能使我的模拟按键实际设置输入值?
我正在制作一个监控按键事件的指令,并根据按键修改输入的值,我无法对此进行测试,直到我能够真正看到模拟的按键实际上改变了文本输入的值。 / p>
describe('testingKeypress', function () {
var context;
beforeEach(inject(function($injector) {
context = this;
this.compile = $injector.get('$compile');
this.rootScope = $injector.get('$rootScope');
this.document = $injector.get('$document');
this.scope = this.rootScope.$new();
this.pressKey = function (keyCode) {
var e = $.Event('keypress');
e.keyCode = keyCode;
e.which = keyCode;
context.el.find('input').trigger(e);
};
this.createElement = function () {
context.el = angular.element('<form><input></form>');
context.compile(context.el)(context.scope);
context.scope.$digest();
};
}));
afterEach(function() {
this.scope.$destroy();
});
describe('making sure an input actually gets some text', function () {
beforeEach(function () {
this.createElement();
this.pressKey(65);
this.pressKey(66);
this.pressKey(67);
});
it('works', function () {
expect(this.el.find('input').val()).toEqual('ABC');
});
});
});
PhantomJS 2.1.1(Mac OS X 0.0.0)确保输入实际上有一些文本无法正常工作 期待&#39;&#39;等于ABC&#39;。