Skip to content
This repository has been archived by the owner on Mar 15, 2023. It is now read-only.

how to wait for all models to be ready? #158

Closed
Freundschaft opened this issue Sep 23, 2019 · 3 comments
Closed

how to wait for all models to be ready? #158

Freundschaft opened this issue Sep 23, 2019 · 3 comments

Comments

@Freundschaft
Copy link

right now I have my services set up like this according to the feathers generator:

const { Service } = require('feathers-mongodb');

exports.AdminAction = class AdminAction extends Service {
  constructor(options, app) {
    super(options);

    app.get('mongoClient').then(db => {
      this.Model = db.collection('admin-actions');
    });
  }
};

This works, but when I try to run tests, my problem is, that during application start, the models are not set yet, because the promise hasn't resolved yet. This makes all my tests fail, because they can't access the model in order to run database queries.

What is the recommended solution for this scenario?

Thanks & Best Regards

@Freundschaft
Copy link
Author

I can see that this is somehow related to this issue on feathers: feathersjs/feathers#509

@daffl
Copy link
Member

daffl commented Sep 23, 2019

In your tests you should be able to

before(async () => {
  await app.get('mongoClient');
});

@Freundschaft
Copy link
Author

Freundschaft commented Sep 23, 2019

Thanks, that worked! Would be nice if feathers generate would consider that in the automatically generated tests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants