ExtJS 4.2.1模拟Ext.Ajax.request(ExtJS 4.2.1 mocking Ext.Ajax.request)
对于使用jasmine的前端单元测试,我想在我的应用程序中模拟我的所有请求。
我已经实现了一个方法来模拟我的所有代理。
proxy: appname.classes.proxy.ProxyNegotiator.getModelProxy("User")
这个方法做的是这样的:
getModelProxy: function(config) { var url = this.getUrl(config); if (this.getProxyType() == 'api') { return appname.classes.proxy.WebApiProxy.getModelProxy(url); } else if (this.getProxyType() == 'test') { return appname.classes.proxy.LocalTestProxy.getModelProxy(url); } return undefined; }
所以你可以想象,根据我的ProxyType配置,我得到web api代理或本地代理进行测试。 我现在已经覆盖了我的粗暴行动..
不过,我还有另外一个问题要处理..我的应用程序中还有其他一些请求,如此(用户名的验证):
//check if Username is Valid Ext.Ajax.request({ url: '/api/User', method: 'GET', async: false, params: { id: user.get('Id'), username: user.get('UserName') }, failure: function(response, opts) { myErrors.push({ field: 'UserName', message: appname.locale.ErrorInvalidUsername }); } });
我确实有一些麻烦嘲笑这个Ext.Ajax.request的东西......我已经在网上搜索过了,并没有找到任何好的解决方案。 什么是模拟此请求的最佳做法? 我很高兴你能给我的每一个暗示和/或想法。 请帮忙!
For frontend unit testing with jasmine i want to mock all my requests in my application.
I've already implemented a method to mock all my proxies.
proxy: appname.classes.proxy.ProxyNegotiator.getModelProxy("User")
and this method does something like this:
getModelProxy: function(config) { var url = this.getUrl(config); if (this.getProxyType() == 'api') { return appname.classes.proxy.WebApiProxy.getModelProxy(url); } else if (this.getProxyType() == 'test') { return appname.classes.proxy.LocalTestProxy.getModelProxy(url); } return undefined; }
so you can imagine depending on my ProxyType configuration i get the web api proxy or the local proxy for testing. I do now have covered my crud operations..
Still, i do have another issue to deal with.. I do have some other requests in my application like this (validation of the username):
//check if Username is Valid Ext.Ajax.request({ url: '/api/User', method: 'GET', async: false, params: { id: user.get('Id'), username: user.get('UserName') }, failure: function(response, opts) { myErrors.push({ field: 'UserName', message: appname.locale.ErrorInvalidUsername }); } });
I do have some troubles with mocking this Ext.Ajax.request things... I've already searched in the web and did not find any nice solution for this. Whats best practice to mock this request? I am glad about every hint and/or idea u can give me. Please HELP!
原文:https://stackoverflow.com/questions/19592934
最满意答案
我有一个使用以下配置的工作设置。 我没有尝试过区域占位符,但据Github说,它可以正常工作。
eureka: provider: enabled: true accounts: - name: myaccount regions: - us-west-2 readOnlyUrl: "http://myeurekahost:8080/eureka"
I have a working setup with the below configuration. I have not tried the region placeholder, but according to Github, it will work correctly.
eureka: provider: enabled: true accounts: - name: myaccount regions: - us-west-2 readOnlyUrl: "http://myeurekahost:8080/eureka"
相关问答
更多-
如何向Spring Cloud和Netflix的Eureka注册Node应用程序(How to Register Node app with Spring Cloud and Netflix's Eureka)[2021-10-29]
您可以创建一个Sidecar应用程序,就像创建任何spring-boot应用程序一样: @EnableSidecar @SpringBootApplication public class SideCarApplication { public static void main(final String[] args) { SpringApplication.run(SideCarApplication.class, args); } } 重要的是你必须配置它才能正确注 ... -
我现在能够解决这个问题。 我在application.yml文件中缺少CloudFoundry PORT环境变量。 这个链接解释了这个问题。 现在, application.yml文件看起来像belwo: # HTTP Server server: port: ${vcap.PORT} # Spring properties spring: application: name: ${vcap.application.name} cloud: services: r ...
-
我有一个使用以下配置的工作设置。 我没有尝试过区域占位符,但据Github说,它可以正常工作。 eureka: provider: enabled: true accounts: - name: myaccount regions: - us-west-2 readOnlyUrl: "http://myeurekahost:8080/eureka" 请参阅https://github.com/spinnaker/cloud ...
-
实际上它是一个试图避免网络分区问题的功能,当你的eureka看不到有服务的服务器,但eureka的客户端与它们有联系。 缺乏快速取消注册对我来说是一种痛苦。 我试图调整它,但没有运气,所以我只是在eureka配置中关闭此功能(这可能不推荐但是..): eureka: server: enableSelfPreservation: false actually its a feature which is trying to avoid network partition issues, whe ...
-
首先,您应该像Google Home一样回复。 您必须回复有效输出,否则它将拒绝您。 因此,不要试图在您的响应中过于花哨 - 只需使用它来避免混乱您的分析和日志。 健康检查看起来像普通的欢迎请求。 ping将包含一个名为is_health_check的参数,其boolValue为true, textValue为1.如果您使用Dialogflow,这将是originalRequest.data.inputs[0]中的参数之一。 对于Actions SDK,它将位于data.inputs[0] 。 以下是Dia ...
-
你的陈述 “我可以启用或禁用项目的健康检查,但不能针对项目下的特定服务。” 是不正确的。 每个服务都有自己的app.yaml文件,您可以通过它配置特定服务的健康检查。 如何做到这一点已在您提供的链接中解释。 Your statement "I can enable or disable the health check for a project, but not for a particular service under a project." is incorrect. Each service ha ...
-
Turbine不知道通过Eureka的每个应用程序的contextPath(Turbine doesn't know contextPath of each application through Eureka)[2022-03-29]
您只能在普通涡轮机中一次查看一个群集。 使用spring-cloud-netflix-hystrix-amqp,我们通过rabbitmq(而不是http)汇总所有统计信息,因此您可以立即查看所有内容。 You can only view one cluster at a time in normal turbine. With spring-cloud-netflix-hystrix-amqp we aggregate all statistics via rabbitmq (not http), so y ... -
您可以通过实施HealthIndicator来开发自己的健康指标,以检查后端应用的健康状况。 所以本质上这不会太困难,因为你可以使用你开箱即用的RestTemplate,例如 public class DownstreamHealthIndicator implements HealthIndicator { private RestTemplate restTemplate; private String downStreamUrl; @Autowired public ...
-
使用特定端口在eureka中注册spring boot https应用程序(Register spring boot https application in eureka with specific port)[2022-07-10]
最后,我已经解决了我的问题。 不确定它是最好的,因为据我所知,它不适用于随机端口,即server.port = 0.在这种情况下,eureka注册应用程序端口0和仪表板上有链接端口不转发纠正位置,这不是预期的行为。 我不得不使用与当前应用程序相关的$ {server.port}占位符,而是使用eureka配置的一部分$ {eureka.instance.secure-port},即 server: port: 9999 context-path: /ctx ssl: key-store: ... -
与ALB运行状况检查一起使用的URL必须返回介于200和399之间的值。此外,必须使用可接受的响应值配置ALB。 资料来源: http : //docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-health-checks.html 其他任何事情都会导致失败: 401将导致失败。 如果301没有配置ALB,那么301将导致失败。 要传递ALB运行状况检查,您必须提供可以返回可接受状态代码的URL。 它可以是专用于运 ...