I'm using Oboe.js, oboe-promise (wraps oboe calls in a promise), and Jest. I'm probably doing something stupid. Any suggestions? Thanks.
My code
"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
My test file
"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'}}]))
})
})
When I run my Jest test I get "Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout." I've added jest.setTimeout(60000) and get same result. I have other Jest tests that test asynchronous non-oboe code and they work fine using the async/await
test('run', async () => {
expect(await <codeToTest>).toEqual(<expected>)
})
pattern.
The code works if I run the code outside of Jest using:
"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()
Well I switched from Jest to Mocha and now the tests work.