首页 \ 问答 \ 单元测试react-router onEnter / onLeave(Unit Test react-router onEnter/onLeave)

单元测试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 using clearInterval.

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);
}

相关问答

更多
  • 呵呵,我也正在学习这个。建议你找点文档看看吧,一两句话讲不清楚的。这东西蛮重要也挺有趣的,同分享。
  • 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 ...
  • 这与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 - 好吧,一些代理,特别是IBM WebSphere MQ,RSMB和mosquitto--支持桥的概念 - 它为主题启用了卫星,网格和树层次结构。 您当然不可能有数百万个客户端连接到单个代理(但上述所有实现都可以很好地扩展到数十万个)。 您需要考虑代理的主题布局和物理层次结构,以及连接的负载平衡和本地化。 Scaling is an issue in any system. MQTT - well, some brokers, specifically IBM WebS ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。