我正在用React开发一个Electron桌面应用程序。尝试设置代码电子侧的测试。我有一个Launch.test.js文件,我正在尝试使用Jest测试Spectron。当我运行测试文件时,它会抛出错误。无法更正错误。
我的文件结构是这样的
node_modules
public
src
--components
--tests
--Launch.test.js
main.js
package.json
README.md
Run Code Online (Sandbox Code Playgroud)
而且Launch.test.js的代码如下所示-
const Application = require('spectron').Application;
const path = require('path');
let electronPath = path.join(__dirname, '..', '..', 'node_modules', '.bin', 'electron');
if (process.platform === 'win32') {
electronPath += '.cmd';
}
const appPath = path.join(__dirname, '..', '..');
const app = new Application({
path: electronPath,
args: [appPath],
});
describe('Test Example', () => {
beforeEach(() => {
return app.start();
});
afterEach(() => {
return app.stop();
});
it('opens a window', () => {
expect.assertions(1);
return app.client.element('input').getValue().then((j) …Run Code Online (Sandbox Code Playgroud) 我有一个像下面这样的对象。
{
A: { lists: 2, list: [ [Object], [Object] ] },
B: { lists: 2, list: [ [Object], [Object] ] },
C: { lists: 1, list: [ [Object]] }
}
Run Code Online (Sandbox Code Playgroud)
在我对对象列表结果进行映射后,如下所示
const list = Object.entries(result).map(([k, v]) => ({[k]: v.lists}));
Run Code Online (Sandbox Code Playgroud)
我得到的结果是
[{"A":2},{"B":2},{"C":1}]
Run Code Online (Sandbox Code Playgroud)
但我真正想要的是
{A: 2, B: 2, C: 1}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?