单元测试react-router onEnter / onLeave(Unit Test react-router onEnter/onLeave)
我在onEnter / onLeave上运行了一些逻辑。 我在onEnter上使用了一些
setInterval
,并使用clearInterval
在onLeave上清除它们。我如何对上述情况进行单元测试?
<Route component={App} onEnter={onEnterApp} onLeave={onLeaveApp} path="/app">
以下是我的测试用例,但失败了,
import React from 'react'; import App from '../components/views/app.jsx'; import {shallow, mount, render} from 'enzyme'; import {expect, assert} from 'chai'; import sinon from 'sinon'; import {mountWithIntl} from '../test_utils/intl-enzyme-test-helper.js'; describe(‘App renders correctly', () => { it('When mounting set intervals', () => { const wrapper = mountWithIntl(<App/>); expect(window.x).to.exist; expect(window.y).to.exist; }); it('When unmounting clear intervals', () => { const wrapper = mountWithIntl(<App/>); wrapper.unmount(); expect(window.x).to.not.exist; expect(window.y).to.not.exist; }); });
I've some logic runs at onEnter/onLeave. I've used some
setInterval
at onEnter and clear them at onLeave usingclearInterval
.How can I unit test above case?
<Route component={App} onEnter={onEnterApp} onLeave={onLeaveApp} path="/app">
Below is my test case but it fails ,
import React from 'react'; import App from '../components/views/app.jsx'; import {shallow, mount, render} from 'enzyme'; import {expect, assert} from 'chai'; import sinon from 'sinon'; import {mountWithIntl} from '../test_utils/intl-enzyme-test-helper.js'; describe(‘App renders correctly', () => { it('When mounting set intervals', () => { const wrapper = mountWithIntl(<App/>); expect(window.x).to.exist; expect(window.y).to.exist; }); it('When unmounting clear intervals', () => { const wrapper = mountWithIntl(<App/>); wrapper.unmount(); expect(window.x).to.not.exist; expect(window.y).to.not.exist; }); });
原文:https://stackoverflow.com/questions/41445865
更新时间:2022-02-24 09:02
最满意答案
在ActiveMQ Spring使用者中,http消息是文本消息的类型,而mqtt消息是BytesMessage的类型。 因为我添加了一些代码
if (message instanceof BytesMessage) { BytesMessage bm = (BytesMessage) message; byte data[]; data = new byte[(int) bm.getBodyLength()]; bm.readBytes(data); msgText = new String(data); System.out.println("Message String = "+msgText); }
in ActiveMQ Spring consumer, the http message is the type of text message and mqtt message is the type of BytesMessage. because am add some code
if (message instanceof BytesMessage) { BytesMessage bm = (BytesMessage) message; byte data[]; data = new byte[(int) bm.getBodyLength()]; bm.readBytes(data); msgText = new String(data); System.out.println("Message String = "+msgText); }
相关问答
更多-
用Java 如何实现ActiveMQ与MQTT的通信?请高手指点.[2021-10-17]
呵呵,我也正在学习这个。建议你找点文档看看吧,一两句话讲不清楚的。这东西蛮重要也挺有趣的,同分享。 -
是不是有一款什么手机软件,可以很自然的拉长腿部?不是美图秀秀,有知道的不?[2022-10-20]
spring -
春天的英语怎么读?[2022-05-21]
spring -
好的,我知道了。 这是一个错误(我认为)。 ActiveMQConnectionFactoryConfiguration创建一个名为“jmsConnectionFactory”的bean,但是查看你的stacktrace(上面)Spring Integration正在寻找要命名的bean:'connectionFactory' 编辑: INT-3941已打开 解决方法: @Configuration public static class SpringBootVsIntegraionWorkaround { ...
-
将消息发送到主题并为地址和队列启用自动创建时,只会创建地址而不是队列。 如果队列是自动创建的,并且消息被放入队列中,这将违反主题的语义。 仅在响应订户时创建主题地址上的订阅队列。 因此,在发送消息之前,您需要有关该主题的订阅者,否则将丢弃该消息(根据主题语义)。 When a message is sent to a topic and auto-creation is enabled for both addresses and queues only the address will be create ...
-
Spring Mqtt集成(Spring Mqtt Integration)[2022-08-21]
这与MQTT无关,您的MqttInboundBeans对您没有声明的UserService类型的Bean具有@Autowired依赖性。 编辑 新增示例: @SpringBootApplication @Controller public class So42578862Application { public static void main(String[] args) { SpringApplication.run(So42578862Application.class, a ... -
我只是测试了你的流,它对我来说工作得很好...... $ cat /tmp/xd/output/mqtttestfile.out foo bar (在我将消息foo和bar添加到队列后)。 为org.springframework.integration启用DEBUG日志记录(在容器的logback.grooy文件中),我看到... 2017-03-04T08:02:59-0500 1.3.1.RELEASE INFO DeploymentsPathChildrenCache-0 endpoint.Ev ...
-
ActiveMQ支持MQTT,你可以在这里阅读: http://activemq.apache.org/mqtt.html 在最近几周,MQ遥测传输中更改了消息队列遥测传输的首字母缩写,因为MQTT没有队列概念! :-) 正如@hardillb所说,发布和订阅操作是在主题上执行的。 “队列”的概念仅在您使用高级“干净会话”到虚假功能时实现,这些功能意味着代理保存在客户端脱机的主题上发布的消息,这样当客户端将返回在线时,它将收到消息。 但是,此实现与代理严格相关(队列不需要)。 我写了以下免费电子书(专注于微 ...
-
在ActiveMQ Spring使用者中,http消息是文本消息的类型,而mqtt消息是BytesMessage的类型。 因为我添加了一些代码 if (message instanceof BytesMessage) { BytesMessage bm = (BytesMessage) message; byte data[]; data = new byte[(int) bm.getBodyLength()]; ...
-
MQTT主题缩放(MQTT Topic Scaling)[2021-10-19]
缩放是任何系统中的问题。 MQTT - 好吧,一些代理,特别是IBM WebSphere MQ,RSMB和mosquitto--支持桥的概念 - 它为主题启用了卫星,网格和树层次结构。 您当然不可能有数百万个客户端连接到单个代理(但上述所有实现都可以很好地扩展到数十万个)。 您需要考虑代理的主题布局和物理层次结构,以及连接的负载平衡和本地化。 Scaling is an issue in any system. MQTT - well, some brokers, specifically IBM WebS ...