Trying out a TypeScript class created with Jasmine testing

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.

Answer №1

If you're having trouble with your spec/movieSpec.js file, consider updating the require statement to:

const Movie = require('../dist/movie').Movie;

It seems like your current require statement may not be returning the correct Movie class. You can verify this by inspecting the value stored in your Movie constant.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to insert a new element into an array without the use of any predefined functions

I've been pondering these two inquiries related to the JavaScript programming language: Is there a method to add elements to an array without relying on the push() function or any other predefined functions in the language? Can two arrays be com ...

Troubleshooting Cross-Origin Read Blocking with the Google Maps Elevation API using Axios in a Vue.js Application

I'm currently working on integrating the Google Maps API into a Vue.js project. I've encountered an issue with two Google Maps services: - The Time Zone API is functioning properly. - However, the Elevation API is giving me a Cross-Origin Read Bl ...

What is the code in CodeIgniter to retrieve the string 'Sugar & Jaggery, Salt' using <a>?

Can someone please help me? I am a beginner in CodeIgniter and I am having trouble passing a URL with a string. The controller is not accepting the string as expected. How can I fix this issue? //Below is the HTML code for passing a string value index.ph ...

What is the proper way to perform date validation using the moment library in JavaScript?

I am facing an issue with the departure date validation on my website. I have a textbox called txtDepartureDate where users can choose the date of departure. The requirement is that if the selected date is before today's date, an error message should ...

Creating a custom enum using generics in TypeScript can be excessively intricate

Is there a simpler way to streamline this code? It feels very repetitive and not quite right... const FolderVisibility = new Enum<{ PUBLIC: 'public', PRIVATE: 'private' }>({ PUBLIC: 'public', PRIVATE: &a ...

Is there a way to transfer HTML code from a textarea to CKEDITOR for setData?

My goal is to retrieve data from a textarea element and use it as setData for CKEDITOR. However, instead of receiving the HTML code, I am only getting the code as a string, which is not rendering properly as HTML. Here's the code snippet: CKEDITOR.re ...

Tips for expanding the width of Bootstrap modal using animation

Is there a way to resize my Bootstrap 5 modal width and add an animation effect when it expands? I've tried using animate and transition in my style-css but haven't had any success so far. I've looked at other solutions online, but none seem ...

Preserve Vue route parameters when the page is refreshed

I am looking for a way to pass a list of meta/props to multiple components based on the route. Currently, I have hardcoded the todo list, and it is not dynamically loaded. My current solution only works when I click from the list to go to an item. However, ...

Looking for assistance with accessing elements using the "document.getElementById" method in Javascript

Below is the code snippet I am working with: <html> <head> <script> function adjustSelection(option) { var selectList = document.getElementById("catProdAttributeItem"); if (option == 0) { ...

Encountered an issue during the npm install process for an Angular project

Below is the content of the package.json file: { "dependencies": { "@angular/animations": "^9.1.3", "@angular/cdk": "^11.1.1", "@angular/common": "^9.1.3", "@angul ...

The functionality of the mathjs eval function varies when used with and without a string input

When I calculate Arithmetic operations using the math.eval function without quotes, null values are ignored and correct results are obtained. However, if I use quotes in the same function, it throws an error. The issue is that I require strings because I ...

Querying an XML document to locate a specific element/attribute value and extract that element

After writing a code that extracts elements from an XML product catalog and displays them in a table, I now aim to retrieve only one specific product with all its details based on a given SERIAL. For instance, I want to fetch the product from the catalog b ...

Guide on how to retrieve a server-generated message within a jQuery script on an EJS page

Is there a way to retrieve and utilize a variable passed from a controller to an EJS page in a jQuery script? Below is the code snippet for reference: app.get('/form', (req, res) => { res.render('form', { errorMessage: & ...

What could be the reason behind the malfunction of my jQuery .css method?

I am currently working on a taglist that allows users to add and remove tags, connected with mySQL. I have successfully retrieved the tags from the database using an ajax call, but I am unable to perform any operations on them, not even apply a basic style ...

Struggling with "Content" not being recognized in Typescript PouchDB transpilation errors?

I have been diligently working on an Ionic app for the past three months with no major issues during development or deployment to mobile devices. However, yesterday I encountered a frustrating NPM dependency problem while trying to deploy to mobile. In an ...

The performance of dom-repeat may be impacted when dealing with sizable objects, such as those containing base64 encoded images

Currently, I am encountering an issue while generating a dom-repeat using a list of objects. Each object in the list has an imgUrl key containing a large base64 encoded image. However, when I generate the dom-repeat in this manner, each item appears undef ...

How can I create numerous HTML containers using Javascript?

I've been learning from this tutorial: Instead of just displaying the last database object, I want to display all of them. I have tried outputting the database contents and it's working fine. Now, I just need to adjust the HTML. I attempted to ...

Tips for designing a seamless automated application guide/tutorial

Currently developing a web application using AngularJS, I am interested in implementing an automated walkthrough or app tour similar to what Google or Facebook do when introducing new features or buttons. I would appreciate any tutorials or guidance from ...

Unable to select a date once the month view has been altered - fullcalendar

My use of the fullcalendar involves indicating the available days for ordering a courier service. Customers can select from any of the two days following today, excluding weekends (Saturday and Sunday). However, when switching to month view, it seems that ...

Angular: searcher function behaves differently based on the type of data being filtered

Can you quickly check out these two examples and tell me why one is working while the other isn't? Here is the first example with real json data extracted from my app, which is not working: http://plnkr.co/edit/2Z5SMlANCGd3r4Trfwzm?p=preview And her ...