Saturday 1 April 2017

gulp + mocha + typescript unit test

I have an error when I create new instance on test file. This is my test:

    /// <reference path="../typings/globals/mocha/index.d.ts" />

import Person from '../src/person/person';

describe('Person', () => {

    let person: Person;

    beforeEach(() => {
        person = new Person();

    });

    describe('getName', () => {

        it('return name', () => {

        });
    });
});

And my gulp task:

var gulp = require("gulp");
var ts = require("gulp-typescript");
var mocha = require("gulp-mocha");
var tsProject = ts.createProject("./tsconfig.json");

gulp.task('watch', function () {
    gulp.watch('./src/**/**/*.ts', ['ts']);
});

gulp.task('ts', function () {
    return tsProject.src()
        .pipe(tsProject())
        .js.pipe(gulp.dest("dist"));
});

gulp.task('test', function () {

    return gulp.src('./tests/*.spec.ts',
        {
            base: '.'
        })
        /*transpile*/
        .pipe(tsProject())
        /*flush to disk*/
        .pipe(gulp.dest('.'))
        /*execute tests*/
        .pipe(mocha())
        .on("error", function(err) {
            console.log(err)
        });
});

gulp.task("default", ['watch', 'ts']);

So, when I launch the test an error occured, but if I comment person = new Person() then everything works.

Somebody knows what I am doing wrong?



via Gustavo Bueno

No comments:

Post a Comment