Cannot find module in jasmine spcs with gulp and browserify

时间:2015-10-06 09:03:47

标签: unit-testing jasmine gulp browserify gulp-jasmine

I am setting up gulp/jasmine with a project running with browserify. I am using absolute paths to load modules. E.g. modules/deposit/card

When I want to load this module in my spec file to test it with jasmine, I am getting an error: Cannot find module 'card'. If i change the path to relative, then I get an error from require within the card.js file where another module is required using an absolute path. Looks like if I had everywhere relative path used, I would not have problems with loading modules in spec files. How can I teach my spec file to load modules via absolute path?

GulpFile.js

...
var jasmine     = require('gulp-jasmine');
...

gulp.task('jasmine', function () {
    return gulp.src('app/js/**/*.spec.js')
        .pipe(jasmine());
});

card.spec.js

/* jslint node: true */
/* global describe, it, expect, beforeEach */

'use strict';

var CardView = require('modules/deposit/card');//throws and error : 'Cannot find module 'card''

describe('Card.js', function() {
    var view, template, collection;

    beforeEach(function() {
        view = new CardView();
    });

    describe('When view is initialized', function() {
        it('template should be defined', function() {
            expect(template).toBeDefined();
        });
    });

    describe('without collection', function() {
        it('should throw exception', function() {
            expect(function() {
                new CardView();
            }).toThrow(new Error('collection is required'));
        });
    });
});

And I want to see test results in the console where I run gulp serve.

0 个答案:

没有答案