0

I've got gulp-jasmine-phantom running, but I get a ReferenceError: Tictactoe is not defined. I have the feeling I'm making some fundamental mistake.

My file-structure:

gulpfile.js
spec/test.js
source/js/tictactoe.js

A simplified version of the code:

gulp:

gulp.task('site:js:test', function() {
return gulp.src( 'spec/test.js')
    .pipe(jasmine())});

test.js:

require("../source/js/tictactoe");

describe("Tictactoe", function() {
  var t = new Tictactoe();
  it("expects there to be able to add a mark", function() {
    t.addMark([0,0], 1);
    expect(t.board[0,0]).toBe(1);
  });
});

tictactoe.js

function Tictactoe(size) {
  this.size = size;

  // default variables:
  this.EMPTY = "";
  this.board = [];

  for ( var i = 0; i < this.size; i++ ) {
    this.board[i] = [];
    for ( var j = 0; j < this.size; j++) {
      this.board[i][j] = this.EMPTY;
    }
  }
}

Tictactoe.prototype.addMark = function(position, player)
{}

I've also tried gulp.src( ['source/js/tictactoe.js', 'spec/test.js'] ) and then no require in the test.js. Also no success. I've also tried gulp-jasmine and gulp-jasmine-browser. Can you help me make it work?

Thanks so much in advance!!

Matthijs
  • 5
  • 4

1 Answers1

0

A related question to yours has been answered already over here: How to Load a File for Testing with Jasmine Node?

In short, you will need to create a module out of your tictactoe library, export the Tictactoe function, and then require it into a local variable that is accessible by Jasmine. The Tictactoe function is currently simply scoped into the local scope of the required JavaScript file.

Community
  • 1
  • 1
Carl in 't Veld
  • 1,363
  • 2
  • 14
  • 29