mardi 14 novembre 2017

How to use mongodb from ember acceptance test?

I use ember mocha for testing, and I don’t know why I can’t use the package npm mongodb from my acceptance test.

In my acceptance test I import :

` import mongodb from ‘myproject/app/helpers/mongodbp’;

In this file mongodbp.js I have :

    import  mongodb  from 'npm:mongodb';
export default mongodb;

But when I use mongodb from my acceptance test, I catch the following error :

‘TypeError: net.createConnection is not a function*********’

/* jshint expr:true */
import {
  describe,
  it,
  after,
  before,
  beforeEach,
  afterEach
} from 'mocha';
import { expect } from 'chai';
import Ember from 'ember';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import { LoginPage } from './LoginPage';

import mongodb from 'myApp/helpers/mongodbp';

describe('Acceptance: Users', function () {
  this.timeout(15000);

  var application;

  beforeEach(function () {  
    application = startApp();

    mongodb.MongoClient.connect('mongodb://localhost:27017/myDb', function (err, db) {
      if(err)
        {
            console.log("***************************"+err+"************************************");
        }
        else {
        // Fetch a collection
        var collection = db.collection('users');

        // Insert a document (insert user)
        collection.insertOne(jsonfile, function (err, result) {

            // Force close the connection
            db.close();
        });
      }

    });

    var page = new LoginPage();
    page.loginmyApp();
  });

  after(function () {
    Ember.run(application, 'destroy');
  });

  it('consult user added', function () {

   click('#user-test');
   this.timeout(15000);
   andThen(function () {
    expect(currentPath()).to.equal('users.index');


  });

  });

});

How can I use mongodb from my acceptance tests in the before hook ?

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire