React Native + Jest - 尝试测试异步UDP方法

时间:2017-08-07 12:36:03

标签: reactjs react-native jestjs node-modules

嘿伙计我有这个方法,使用dgram或更具体的反应原生udp库来处理udp协议。

import * as dgram from 'react-native-udp' //dgram only works for react web

export const onMessage = (handleDiscovery: any): any => {
    const socket = dgram.createSocket('udp4')
    socket.bind(3001)
    socket.on('message', function (msg, rinfo) {
        handleDiscovery(msg, rinfo)
    })
}

当我尝试用Jest测试时:

it('ASYNC', () => {
    udp.onMessage((msg, rinfo) => {
        console.log(msg, rinfo)
        expect(1).toBe(1)
    })
})

我收到此错误:

Reducers must work correctly › ASYNC
TypeError: Cannot read property 'createSocket' of undefined

奇怪的是,代码在Android设备中正常工作,但在测试套件上没有。我是否必须重新进行测试?

0 个答案:

没有答案