Looking to test a TypeScript class using Jasmine, I encountered an error when running jasmine spec/movieSpec.js
. The error message "TypeError: Movie is not a constructor" appears. My files are as follows:
src/movie.ts
export class Movie {
private name: string;
constructor(name: string) {
this.name = name.replace(".mkv", "");
}
}
dist/movie.js (generated)
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Movie {
constructor(name) {
this.name = name.replace(".mkv", "");
}
}
exports.Movie = Movie;
spec/movieSpec.js
const Movie = require('../dist/movie');
describe("Movie", function() {
let movie = new Movie("aMovie.mkv");
it("removes the file extension", function() {
expect(movie.name).toEqual("aMovie")
});
});
package.json
{
"dependencies": {
"@types/jasmine": "^2.8.9",
"ts-node": "^7.0.1"
}
}
Update
Changed the target
in tsconfig.json
to "ES2016"
, resulting in a different movie.js
. However, the error persists.