AngularJS和Socket.IO模型未在事件中更新(AngularJS and Socket.IO model not being updated in event)
这是我的控制器。
app.controller('ChatController', function () { this.username = ''; this.setUsername = function (username) { this.username = username; }; socket.on('success', (function (controller) { return function(username) { $('#password_page').fadeOut(); controller.setUsername(username); $('#chat_page').removeClass('hidden').show(); }; })(this)); });
问题是,当事件'success'以用户名correclty作为参数传递时,我的控制器中的
this.username
不会更新。我怎样才能解决这个问题?
This is my controller.
app.controller('ChatController', function () { this.username = ''; this.setUsername = function (username) { this.username = username; }; socket.on('success', (function (controller) { return function(username) { $('#password_page').fadeOut(); controller.setUsername(username); $('#chat_page').removeClass('hidden').show(); }; })(this)); });
And the problem is that when the event 'success' fires with the username correclty passed as an argument, the
this.username
in my controller doesn't get updated.How can I fix this?
原文:https://stackoverflow.com/questions/31228007
最满意答案
问题出在您的
getAttribute()
标签上,当您在文本框字段中输入文本时,您可以通过value
属性访问输入的文本。所以你的
expect
断言如下 -expect(articleName.getAttribute('value')).toEqual('Test Item Edited');
The issue is with your
getAttribute()
tag, when you are entering text in a textbox field , you could access the entered text withvalue
attribute.So your
expect
assertion would be as follows-expect(articleName.getAttribute('value')).toEqual('Test Item Edited');
相关问答
更多-
您可以使用isPresent测试element是否存在。 以下是 isPresent函数的量角器文档 。 所以,你的代码会是这样的: var myElement = element(by.css('.elementClass')); expect(myElement.isPresent()).toBeFalsy(); You can test whether the element is present with isPresent. Here are the protractor docs for th ...
-
这应该做到: expect($('[ng-show=saving].icon-spin').isDisplayed()).toBeTruthy(); 记住量角器的$不是jQuery和:visible还没有可用的CSS选择器+伪选择器的一部分 更多信息, 请访问https://stackoverflow.com/a/13388700/511069 This should do it: expect($('[ng-show=saving].icon-spin').isDisplayed()).toBe(tru ...
-
您可以使http请求同步 - 在大多数情况下,这是一件坏事。 或者,您可以将回调插入到execute函数中: var flow = protractor.promise.controlFlow(); var result = flow.execute(function() { var defer = protractor.promise.defer(); request('http://localhost/test/recipe/person', function (error, respo ...
-
并尝试检查这样的复选框,但当我运行测试时似乎没有检查它: 那是因为你点击了转发器项 - div元素,但我需要点击input子元素。 您可以在单个表达式中链接 .all()和.element()调用: this.environments.first().element(by.css("input[ng-model$=checked]")).click(); And trying to check the checkbox like this but when i run the test it does n ...
-
你在正确的轨道上。 因为findElements返回一个数组,所以你只需要改变if (result.length>0) if (result)含义。 使用FindElements,找不到任何东西都不是错误。 You were very much on the right track. Because findElements returns an array, you just needed to change what you had if (result) to if (result.length>0) ...
-
问题出在您的getAttribute()标签上,当您在文本框字段中输入文本时,您可以通过value属性访问输入的文本。 所以你的expect断言如下 - expect(articleName.getAttribute('value')).toEqual('Test Item Edited'); The issue is with your getAttribute() tag, when you are entering text in a textbox field , you could access ...
-
这里发生的是因为你的断言是在异步操作的回调中,测试在遇到expect(text).to.equal(myText);之前完成expect(text).to.equal(myText); 声明,因此通过。 您需要确定测试不应该通过,直到您等待的承诺得到解决! 根据Chai关于承诺的文件,我认为你应该使用的模式是: expect(selectedElement.getText()).to.eventually.equal(myTest); I've found two fixes for this probl ...
-
如果元素刚刚出现并且不在DOM中,那么首先需要等到它存在并且在检查之前看到它,然后再检查它。 总体来说是这样的: public isNoLongerPresent(elem) { //NOTE: If any of the expected conditions don't happen, your code times out. //No need for false-check or similar var EC = protractor.ExpectedConditions; ...
-
browser.wait($('puppet-summary').isPresent, 1000); “等待元素存在”应该通过内置的presenceOf预期条件完成 : var EC = protractor.ExpectedConditions; var elm = $('puppet-summary'); browser.wait(EC.presenceOf(elm), 1000); browser.wait($('puppet-summary').isPresent, 1000); The "wai ...
-
您可以使用isPresent() : expect(element(by.binding('invoice.messages')).isPresent()).toBeFalsy(); 这是 isPresent() 的Protractor文档 。 但是,您可能必须选择DOM id或css而不是binding : expect(element(by.id('#id-in-the-dom-for-invoice-messages')).isPresent()).toBeFalsy(); expect(eleme ...