dimanche 29 janvier 2017

ReferenceError: requirejs is not defined at

I am using Mocha with Zombie.js to test my application which uses require.js.

I have the following content in the test.js file:

process.env.NODE_ENV = 'test';

var express = require('express'),
  http =require('http'),
  assert = require('assert');

app = express();
app.use(express.static('src'));

const Browser = require('zombie');

describe('User visits signup page', function() {  
  before(function() {
    this.server = http.createServer(app).listen(3000);
    this.browser = new Browser({ site: 'http://localhost:3000', debug: true, runScripts: true });
  });

  before(function(done) {
    this.browser.visit('/index.html', done);
  });

  describe('submits form', function() {

    before(function() {
      return this.browser;
    });

    it('should be successful', function() {
      this.browser.assert.success();
    });

    it('should see welcome page', function() {
      this.browser.assert.text('title', 'Page Title');
    });
  });

  after(function(done) {
    this.server.close(done);
  });
});

When I am launching the test (with command line mocha test/test.js), I encouner the following error:

User visits signup page
    1) "before all" hook


  0 passing (341ms)
  1 failing

  1) User visits signup page "before all" hook:
     ReferenceError: requirejs is not defined
      at http://localhost:3000/index.html:script:2:10
      in http://localhost:3000/index.html

It seems that somehow Mocha/Zombie doesn't wait for the require.js script to get loaded or something similar. Have you encountered this issue before ? Many thanks.

Aucun commentaire:

Enregistrer un commentaire