gpt4 book ai didi

javascript - Jest messageParent 只能在工作人员内部使用

转载 作者:行者123 更新时间:2023-12-04 11:05:59 24 4
gpt4 key购买 nike

有没有办法得到正确的错误信息?
当我做$npm test我故意破坏我的代码(咳咳去掉一行代码)
我收到这条消息

src/redux/drivers/driver.saga.spec.js
Test suite failed to run

"messageParent" can only be used inside a worker

at messageParent (node_modules/jest-worker/build/workers/messageParent.js:46:11)
我相信这是一个毫无意义的错误消息,如果有一些有意义的东西会很好 (=.
这是我的测试
describe("DriverSocketFlow failed REASON:\n", () => {
let socket;
beforeEach(() => {
socket = new MockedSocket();
io.mockReturnValue(socket);
});
afterEach(() => {
jest.restoreAllMocks();
});
const mockGeneratorPayload = { payload: { name: "Royal Palms" } };
const generator = DriverSocketFlow(mockGeneratorPayload);

test("Checking if DriverSocketFlow was called with it's methods and disconnected gracefully", () => {
expect(generator.next(socket).value).toEqual(
call(connect, mockGeneratorPayload.payload.name)
);
expect(generator.next(socket).value).toEqual(
call(socketbug, mockGeneratorPayload.payload.name)
);
//disconnect gracefully
expect(generator.next(socket).value).toEqual(
fork(Read_Emit_Or_Write_Emit, socket)
);
expect(generator.next().value).toEqual(
take(DriversActionTypes.DRIVERS_SOCKET_OFF)
);
expect(generator.next(socket).value).toEqual(call(disconnect, socket));
expect(generator.next(socket).value).toEqual(call(disconnect, socket));

expect(generator.next().value).toEqual(cancel());
});
});
应该说
DriverSocketFlow 失败原因:

Checking if DriverSocketFlow generator function was called and disconnected gracefully


谢谢!寻找!
……
所以我想我想通了!
这是我的新测试
test("1. Connected to the socket successfully", () => {
expect(generator.next(socket).value).toEqual(
call(Connect_To_Socket, mockGeneratorPayload.payload.name)
);
expect(generator.next(socket).value).toEqual(
call(socketbug, mockGeneratorPayload.payload.name)
);
});
test("2. Read_Emit_Or_Write_Emit generator function operations for socket.on and emit", () => {
expect(generator.next(socket).value.payload.fn).toEqual(
fork(Read_Emit_Or_Write_Emit, socket).payload.fn
);
});
但我认为这是 npm test 中的错误
不知道为什么会这样,但是如果你在 package.json 脚本标签内的 npm test 中停止观察并重新启动测试......它应该可以工作......
"scripts": {
"test": "react-scripts test --watchAll=false",

},
并且....!不知道这一步是否有帮助,但我添加了
根目录中的 jest.config.js 并将其删除然后突然它起作用了......“<-咳咳它可能没有做任何事情只是继续重新启动它¯_(ツ)_/¯....它对我有用”
这是完整的代码
driver.saga.spec.js

最佳答案

在我的情况下,发生错误是因为我试图在数组中使用 toBe 断言,而不是在 array.length
错误的例子:

expect(array).toBe(3)
正确的例子:
expect(array.length).toBe(3)
在您的情况下,期望变量的类型和右侧的答案可能不同。

关于javascript - Jest messageParent 只能在工作人员内部使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66202911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com