New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with ava: TypeError: callback is not a function #204
Comments
what version of node are you using and what OS? |
|
help me out, when you say you are using it with es6, are you using babel, or you are passing some extra flags to node, or ... because when i am running your example as is, I am getting:
|
@winfinit I keep forgetting node.js doesn't implement |
@omnidan I am unable to duplicate this issue here was my setup:
content of a bug/204.es6: "use strict"
import mongoose from 'mongoose'
import mockgoose from '../mockgoose'
mockgoose(mongoose).then(function () {
mongoose.connect('mongodb://example.com/TestingDB', function (err) {
console.log("err:", err);
console.log("done");
mongoose.disconnect();
})
}) running bug/204.es6 script:
my system:
|
I finally managed to get it to work, this is how Mockgoose works fine with
|
Actually this seems to be an issue when using Mockgoose with the test runner |
@omnidan thank you for this bug report and for your time pinpointing this issue. I will set myself up with some tests using ava, and will post updates in this issue. |
I have the same issue. import test from 'ava';
import sut from './server';
import request from 'supertest-as-promised';
import mongoose from 'mongoose';
import mockgoose from 'mockgoose';
test.before(async t => {
console.log('1');
await mockgoose(mongoose);
console.log('2');
const Subscription = mongoose.model('Subscription');
await Subscription.create({ id: 'found' })
});
test('send message to an existent subscription', async t => {
const res = await request(sut).post('/api/found/message');
t.is(res.status, 200);
});
test.after(t => mockgoose.reset(err => {
if (err) t.fail(err)
})); Only the 1 is printed server.js ...
app.get('/api/:subscription/message', async (req, res) => {
const subscription = await Subscription.findOne({ id: req.params.subscription });
if (subscription) {
return res.send(subscription);
}
return res.status(404);
}); |
Are we sure about this? I think the issue is here: https://github.com/mccormicka/Mockgoose/blob/master/Mockgoose.js#L144 mongodb-prebuilt takes a callback and doesn't check before trying to call it. If you don't pass a callback to mongod.start_server() then it errors like that. If you agree I can PR |
@jadamgreen1010 Thanks for the hint! Manually adding a callback to |
@omnidan You're welcome :) I hope so too, although I think it's something that could (maybe should) be fixed on both sides - mongodb-prebuilt could look before it leaps with that callback so we wouldn't have to pass a dummy function just to keep it from erroring. |
@jadamgreen1010 it probably makes sense to add the callback either way (at least to check for errors) 😉 |
@omnidan I'd agree, but it seems (if my memory serves me right) that the cb is only being called when there's an error and not called with success. It looks like the 'startResult' code that start_server returns is the only way handle any case, so the cb would be redundant. It seems to me... |
Any idea if this hotfix will be implemented? I've hit a bit of a roadblock with a project that it fixes for me. |
@jadamgreen1010 @SNeugber @winfinit , not sure why you are using a hacky dummy function instead of a proper check. Since mongodb-prebuilt return error or exit codes !==0 as first argument on the callback, we can embed the code for status check right into the callback. Please check #212 |
Ooops, sorry guys, I see the issues now. I made mongodb-js/mongodb-prebuilt#27 to solve the issue definitely. |
Just as an FYI, you can get around this issue temporarily by running ava in serial mode |
this is pretty old so just wanted to confirm this is an issue. im testing with mocha with no success. i looked at the changes in mongodb-js/mongodb-prebuilt#27 and manually put it in the module with no success either |
I am new to mockgoose and using es2015. I don't know if it is a good place to ask question here. I have already used babel-register and run with mocha. If i am using es6 import, it will load the app before mocking the mongoose. So i can't mock the mongo. Any solutions? I can only mock like this in order to mock before connect the db and use memory rather mongo
Thanks |
I am still having this issue, even with
|
I'm still getting this issue with my tape tests. I can run the tests one at a time but running more than one gives me:
Using mockgoose v6.0.3 & mongoose v4.5.4 |
I moved back to mocha due this bug. I got here from MERN boiler plate. Got this same error when running |
Hello, I am not monitoring this project anymore, please resubmit it under mockgoose/mockgoose if this is still an issue with new 7.x release |
I tried the example from README.md, but with ES6:
However, this fails with the following error:
The text was updated successfully, but these errors were encountered: