我使用的是Oboe.js、双簧管-承诺 (承诺中封装双簧管调用)和取笑。我可能在做傻事。有什么建议吗?谢谢。
我的代码
"use strict";
const oboe = require('oboe-promise')
const { Readable } = require('stream')
class Example {
async run() {
const json = JSON.stringify([{obj1: {name: 'example', value: 5}}, {obj2: {type: 'other', value: 0}}])
const strm = Readable.from(json)
return await oboe(strm)
.node('{type}', (node) => {
node.name = node.type
delete node.type
return node
})
.run()
}
}
module.exports = Example我的测试文件
"use strict"
// Classes
let Example // class under test
// Objects
let example // object under test
describe('Example', () => {
beforeEach(() => {
Example = require('../../src/Example')
example = new Example()
})
test('run', async () => {
expect(await example.run()).toEqual(JSON.stringify([{obj1: {name: 'example', value: 5}}, {obj2: {value: 0, name: 'other'}}]))
})
})当我运行Jest测试时,我得到“异步回调没有在jest.setTimeout指定的5000 ms超时内调用”。我添加了jest.setTimeout(60000)并得到了相同的结果。我还有其他Jest测试,测试异步非双簧管代码,它们使用异步/等待很好地工作。
test('run', async () => {
expect(await <codeToTest>).toEqual(<expected>)
})模式。
如果我在Jest之外运行代码时,代码可以使用:
"use strict";
const Example = require('./Example')
function runIt() {
const ex = new Example()
ex.run()
.then(r => {console.log(r)})
.catch(e => {console.log(e)})
}
runIt()发布于 2021-03-20 19:39:02
我从Jest转到Mocha,现在测试成功了。
https://stackoverflow.com/questions/66710835
复制相似问题