title: How to write unit test for loopback datasource
body: <p>I wish to write unit tests for my mongodb datasource in my Loopback 4 project, however I could not find any examples.</p>
  <p>Below is my datasource:</p>
  <pre><code>import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core';
  import {juggler} from '@loopback/repository';
  
  const arrayStr: string[] = [];
  
  const config = {
    name: 'mongodb',
    connector: 'mongodb',
    // url: '',
    host: 'localhost',
    port: 27017,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    authSource: 'admin',
    database: 'testdb',
    ssl: false, // default to false
    sslValidate: false, // default to false
    useNewUrlParser: true,
    allowExtendedOperators: true,
    sslCA: arrayStr,
  };
  
  
  // Observe application's life cycle to disconnect the datasource when
  // application is stopped. This allows the application to be shut down
  // gracefully. The `stop()` method is inherited from `juggler.DataSource`.
  // Learn more at https://loopback.io/doc/en/lb4/Life-cycle.html
  @lifeCycleObserver('datasource')
  export class MongodbDataSource extends juggler.DataSource
    implements LifeCycleObserver {
    static dataSourceName = 'mongodb';
    static readonly defaultConfig = config;
  
    constructor(
      @inject('datasources.config.mongodb', {optional: true})
      dsConfig: object = config,
    ) {
      super(dsConfig);
    }
  }
  </code></pre>
  <p>I have tried writing a basic constructor test:</p>
  <pre><code>import {MongodbDataSource} from '../../../datasources';
  import {expect} from '@loopback/testlab';
  
  describe('MongoDB Datasource (unit)', () =&gt; {
    // we recommend to group tests by method names
    describe('consturctor()', () =&gt; {
      it('basic constructor', () =&gt; {
        const ds = new MongodbDataSource();
        expect(ds.name).to.equal('mongodb'); // default name
      });
    });
  });
  </code></pre>
  <p>However, tests will hang/stop and not completed. Appreciate any advice.</p>