"Exploring the world of unit testing with Chutzpah and Jasmine in TypeScript

Currently, I am in the process of configuring Chutzpah and Jasmine to work together within visual studio. My main objective is to successfully run unit tests with TeamCity integration.

Whenever I save my code, all TypeScript files are compiled into a single .js file. This triggers Chutzpah to execute my tests, which seems to be functioning correctly thus far.

The problem arises when Chutzpah displays 0 passed, 0 failed, and 0 errors for the test results. Although the Jasmine html file generated correctly lists all of my tests, Chutzpah does not seem to receive any feedback from Jasmine.

A snippet from the trace log reads:

Attempting to create test context for c:\.....\test.ts
Building test context for c:\.....\test.ts
...framework dependencies / other details (~15 lines)
Finished building test context for c:\.....\test.ts
Warning: 0 : Message:Chutzpah detected missing generated .js files, but since the compile mode is External, Chutzpah cannot compile them. Test results may be inaccurate.

Following this, PhantomJS is launched and logs show loading/receiving resources. Surprisingly, my test.ts file is not among the listed resources, while the project-wide .js file is included (upon inspection, it was evident that my tests were appended to this file).

Completed test run for c:\......\test.ts in Discovery mode
Cleaning up test context for c:\......\test.ts
Chutzpah run completed with 0 pass, 0 fail, and 0 errors
Cleared chutzpah.json file cache
Finished Test Adapter Discover Tests

chutzpah.json

{
  "Framework": "jasmine",  
  "EnableTestFileBatching": true,
  "Compile": {
    "Mode": "External",
    "Extensions": [ ".ts" ],
    "ExtensionsWithNoOutput": [ ".d.ts" ],
    "Paths": [
      {
        "OutputPath": "../SiteWide.js",
        "SourcePath": "Views"
      }
    ]
  },
  "References": [
    {
      "Path": "../knockout-3.4.2.js",
      "IsTestFrameworkFile": true
    }
  ],
  "Tests": [
    {
      "Includes": [ "*.ts" ],
      "Path": "../Tests/Views"
    }
  ],
  "EnableTracing": true,
  "TraceFilePath": "./trace.log"
}

tests.ts

describe('configuring unit tests for typescript!', () => {
    it('this should pass', () => {
        expect(1).toBe(1);
    });

    it('this should fail', () => {
        expect(1).toBe(0);
    });
});

I have some suspicions regarding the missing .js files note in the trace log, although it could be related to the single JS compilation step I am using.

Could it be possible that I overlooked referencing Jasmine in my chutzpah.json configuration?

Despite the fact that the Jasmine tests are functioning properly, I am puzzled as to why Chutzpah is not providing any feedback.

Answer №1

It might be a bit late to mention this, but including something similar to the code snippet below in chutzpah.json could be beneficial:

{
"Framework": "jasmine",
"Compile": {
    "Mode": "External",
    "Extensions": [ "*.ts" ],
    "ExtensionsWithNoOutput": [ "*.d.ts" ]
},
"References": [
    { "Path": "node_modules/promise-polyfill/dist", "Include": "*.js", "Exclude": "*.d.ts" },
    { "Path": "node_modules/systemjs/dist", "Include": "*.js", "Exclude": "*.d.ts" }
],
"Tests": [
    { "Path": "unittests", "Includes": [ "*.spec.ts" ], "Excludes": [ "*.d.ts" ], "ExpandReferenceComments": "true" }
]

}

Ensuring that your system-related files are properly included in the references is crucial. Additionally, consider using "*.spec.js" in the Tests section for better compatibility.

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

The module './$types' or its related type declarations could not be located in server.ts

Issue with locating RequestHandler in +server.ts file despite various troubleshooting attempts (recreating file, restarting servers, running svelte-check) +server.ts development code: import type { RequestHandler } from './$types' /** @type {imp ...

Using a generic type as a value in an abstract class <T, K extends keyof T> allows for flexible and dynamic data manipulation

Currently, I am in the process of transferring some logic to an abstract class. Let's look at the abstract generic class with specific constraints: abstract class AbstractVersion< TModel extends object, TProperty extends keyof TModel, T ...

What is the type of return from withRouter?

I'm a beginner with TypeScript and React. I'm encountering an error with Eslint that says "Missing return type on function" in my React HOC that uses withRouter. I'm puzzled about how to define the return type for the filterRedirectHOC funct ...

The Angular2 view is failing to display updated data from a shared service

I've been struggling to show data from my shared service, but it's not displaying. Can someone please help me out? I've been stuck on this for the past few days. I've tried NgZone and ChangeDetectorRef, but they haven't worked for ...

Insert dynamic values into div attributes

I am looking for a way to dynamically add div attributes in Angular 7. Here is what I attempted: <div *ngFor="let e of etats._embedded.etats" style="background: {{e.codeCouleur}} !important;" data-code="{{e.id}}" data-bg={{e.codeCouleur}}>{{e.no ...

Deriving a universal parameter from a function provided as an argument

My function can take in different adapters along with their optional options. // Query adapter type 1 type O1 = { opt: 1 } const adapter1 = (key: string, options?: O1) => 1 // Query adapter type 2 type O2 = { opt: 2 } const adapter2 = (key: string, opti ...

What could be causing my code to fail in retrieving lists from the SharePoint site?

I've been attempting to retrieve lists from a SharePoint site using the provided code, however, the list isn't appearing in the response. Could someone please offer assistance with this issue? I have tried various other solutions, but the problem ...

An issue has been detected with the width attribute in Typescript when using

I have a question regarding the TypeScript error related to the width property. I've created a component called ProgressBar where I'm using Stitches for styling. However, TypeScript is throwing an error even when I specify the type as ANY. impor ...

Constructing an Angular 2 application using a solo TypeScript file that is compiled individually

At the moment, I am in the process of developing a Chrome Extension using Angular 2. The application includes a background.js file which handles the functionality for a long-running task that operates while the extension is active. Currently, this backgrou ...

Typescript Mongoose is unable to recognize an incorrect key

When working with typescript and mongoose, I encountered an issue where mongoose was unable to detect invalid keys and changed all typescript keys to partial. model.ts type Coin = { symbol: string; name: string; } interface IDocument extends Coin ...

Dealing With HttpClient and Asynchronous Functionality in Angular

I've been pondering this issue all day. I have a button that should withdraw a student from a class, which is straightforward. However, it should also check the database for a waiting list for that class and enroll the next person if there is any. In ...

Uh-oh! Angular 6 has encountered an unexpected error with template parsing

I am currently working on an Angular application where I have integrated the FormsModule from '@angular/forms' in my app.module.ts. However, despite this, I keep encountering the error message No provider for ControlContainer. Error log: Uncaug ...

Accessing an unregistered member's length property in JavaScript array

I stumbled upon this unique code snippet that effectively maintains both forward and reverse references within an array: var arr = []; arr[arr['A'] = 0] = 'A'; arr[arr['B'] = 1] = 'B'; // When running on a node int ...

The ng-bootstrap typeahead is encountering an error: TypeError - Object(...) is not functioning correctly

Hey there! I'm trying to integrate the Angular Bootstrap typeahead component in my Angular 5 application by following the linkToTypeahead. However, I'm encountering some errors along the way. Here's what I'm seeing: ERROR TypeError: Ob ...

Error in typescript Autocomplete component from @mui/material

Currently, I am working on implementing an Autocomplete field using react-hook-form. Everything seems to be functioning correctly, but I have encountered a TypeScript error: The provided object does not match the expected type 'AutocompleteProps<{ ...

Angular ngModel failing to accurately reflect changes in input value

I am facing an issue with implementing a smart number input component that can toggle between allowing or disallowing negative numbers. I have an event listener for the (input) on the <input> element, triggering a function that applies various regex ...

steps for correctly deleting a property from an object in TypeScript

I usually use this generic function to delete a key from an object, but I'm open to better solutions if anyone has one: const removeKeyFromObject = <T extends {}, K extends keyof T>(data: T, key: K) => { const updatedData: any = { ...data } ...

Issue with logging messages using console.log in Knex migration script

My concern: I am facing an issue where the console.log('tableNobject: ', tableNobject) does not get logged in my knex migration script. I have attempted the following code snippets: //solution A export async function up(knex: Knex) { const ta ...

Creating a custom event handler for form input changes using React hooks

A unique React hook was created specifically for managing form elements. This hook provides access to the current state of form fields and a factory for generating change handlers. While it works seamlessly with text inputs, there is a need to modify the c ...

Moving the starting directory of a NodeJS application on Azure

My NodeJS app on Azure was initially written in Javascript with the app.js file located in the root directory. This file was automatically detected during deployment via Git. Recently, I converted the app to Typescript and now have a build directory, with ...