[SOLVED] FindOne doesnt work with cypress testing

Hi all i am having a very interesting problem. findOne() seems to work internally differently than find().fetch(), it appears findOne is working more like an async function than a in line function.

my app works fine in real life, but it breaks when run by cypress due to this difference. can someone give me some background on what is going on behind the scenes here?
thanks
chris

I’d need to see the code to say better but two things jump to mind. 1. Are you sure the subscriptions are ready when you’re calling it? And 2. Are you processing the result in the .then(result => ) ?

baiscally something like:

const mycontainer = withTracker(()=>{
const myhandle = Subscache.subscribe (“mycollection”)
if(myhandle.ready()){
const myfile = mycollection.findOne({somefeature: “blah”})
const myid = myfile._id
}

this works with no problem when i run it normally, but when i try to run cypress testing on it myid comes back as undefined all the time. i have done some reading and it appears that findOne() is actualy like find( {} , callback).

what am i missing here?

btw this DEF DOES NOT WORK:
let myid= null;
const mycontainer = withTracker(()=>{
const myhandle = Subscache.subscribe (“mycollection”)
if(myhandle.ready()){
mycollection.findOne({somefeature: “blah”}).then(result=>{
myid = result._id
}

}

You can’t assign things like that in cypress tests. Check out this .
We don’t touch minimongo at all in our tests so can’t share any working example with you.
This article is by far the most useful on cypress & meteor if you haven’t seen it.

1 Like

it was something else in my code, completely different, it works fine now. i have no problem using cypress for acceptance testing.

1 Like