Troubleshooting a JS promise issue with Kriskowal's Q library

I have been working with the kriskowal/q module to create a promise, but I am encountering an issue where it does not enter any function paths - neither the happy path nor the error path.

Below is the class where I create the promise:

var Q = require('q');

var Test = function () {

};

Test.prototype = (function () {
    var testt = function () {
        var deferred = Q.defer();
        var x = 5;
        if (x === 5){
            deferred.resolve('resolved');
        }else{
            deferred.error(new Error('error'));
        }
        return deferred.promise;
    };
    return {
        testt : testt
    }
}());

module.exports = Test;

This is how I am attempting to use the promise:

var Test = require('../src/js/test.js');

describe("Test", function () {
    "use strict";

    var test = null;

    beforeEach(function () {
        test = new Test();
    });

    it("should return the promise", function () {
        test.testt().then(
            function (a) {
                console.log(a);
            },
            function (b) {
                console.error(b);
            }
        );
    });
});

Since this is a jasmine test class, the logic inside the 'it' function demonstrates how I am using the promise created in the 'testt' function. For more details, I have included the full code snippet.

Issue: The promise does not output either variable 'a' or 'b'.

Answer №1

Your task is completing instantly, rather than after the promise has been resolved or rejected.

it("expects a returned promise", function (finished) {
    evaluate.analysis().then(
        function (result) {
            console.log(result);
            finished();
        },
        function (error) {
            console.error(error);
            finished();
        }
    );
});

For further details, check out this link.

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

I'm looking to create a post using two mongoose models that are referencing each other. How can I do this effectively?

My goal is to create a Post with the author being the user who created it and have the Post added to the array of posts in the user model that references "Post". Despite searching and watching tutorials, I'm still struggling to understand how to achie ...

Easy Steps to Simplify Your Code for Variable Management

I currently have 6 tabs, each with their own object. Data is being received from the server and filtered based on the tab name. var a = {} // First Tab Object var b = {} // Second Tab Object var c = {} // Third Tab Object var d = {}// Fou ...

Tips for simulating next/router in vitest for unit testing?

Struggling with creating basic tests for our Next.js application that utilizes the useRouter() hook, encountering errors when using vitest. In search of solutions to mock next/router for unit testing in conjunction with vitest. ...

Can a specific CSS rule be written in Material UI using makeStyles that will only apply if the element has both classes together?

It's common knowledge that achieving this in CSS is a possibility. .makeStyles-mainNavWrapper-67.sticky{ position: fixed; top: 0px; opacity: 1; transition: opacity 1s ease; padding: 10px; } I am curious to find out if this can be achieved ...

The index type 'X' is not allowed for use in this scenario

I encountered an issue in my TypeScript code: error message: 'Type 'TransitionStyles' cannot be used as an index type.' I'm wondering if there's a way to modify my interface so that it can be used as an index type as well: ...

JavaScript fails to focus on dynamically inserted input fields

Within my HTML template, there is an input element that I am loading via an Ajax call and inserting into existing HTML using jQuery's $(selector).html(response). This input element is part of a pop-up box that loads from the template. I want to set f ...

Utilizing Angular to integrate with an external API

I have encountered an issue while trying to connect to the Expedia API. In order to do so, I need an API key and ID. Initially, I utilized JSONP for this connection but ran into a bug causing problems. Additionally, storing my API key in JavaScript poses ...

Customize the appearance of each element in ng-repeat individually

In my code, I have implemented an ng-repeat. Each alternate div inside the ng-repeat is supposed to have a different border-color, which is achieved by using the following structure: <div ng-repeat="channel in channelList"> <div ng-style="get ...

Troubleshooting EasyZoom: Problems stemming from CSS and markup structure

Despite following the documentation correctly, I seem to be encountering an issue. There are no JavaScript errors and the DOM changes reflect my interactions. However, when I hover over the thumbnail, the larger image remains fixed at 0, 0. Removing the ea ...

There is a problem with the Angular document because it is not

I am looking to optimize my Angular app for production by running the following command: npm run build:ssr SSR stands for server-side rendering. However, after completing the build process, I encounter an error within my header components. The error mes ...

Executing JavaScript in Selenium is a common task that can be accomplished by

Attempting to automate a process using Python and Selenium has been successful for me on various websites in the past. However, I am currently facing a challenge with executing JavaScript on a specific site despite finding tutorials online. https://i.ssta ...

"Encountering issues while upgrading Polymer project version from 0.5 to 1.0

I am in the process of upgrading my project from polymer .5 to polymer 1.0. After installing the new version of the polymer library, iron element, and paper element, I encountered the following error: polymer-micro.html:63 Uncaught TypeError: prototype ...

Google Maps API is successfully loading from an HTML file, however, it is not functioning properly when accessed

I am facing an issue while trying to connect to the Google Maps API through an AngularJS application on my localhost. Despite finding the javascript file in the HTML and displaying 'test1' in the console, the `initMap` function is not being calle ...

Able to display the value when printing it out, however when trying to set it in setState, it becomes

Within my form, there's a function that receives the value: _onChange(ev, option) { console.log(option.key) // Value of option key is 3 this.setState({ dropdownValue:option.key }) // Attempting to set state with 'undefined' as ...

"An error message stating 'Express: The body is not defined when

I'm encountering an issue while trying to extract data from a post request using express. Despite creating the request in Postman, the req.body appears empty (console.log displays 'req {}'). I have attempted various solutions and consulted s ...

spinning camera around a globe with javascript and three.js

In my project, I am working on enabling a player to navigate in a first-person view on a planet using three.js and JavaScript. There are two key aspects I am focusing on: a) Implementing player movement around the planet, which involves two types of movem ...

Angular-Loopback-SDK: The method prototype$updateAttributes is not functioning as expected

I'm currently utilizing the loopback-angular-sdk and encountering a strange error while using the updateAttributes function: MyModel.prototype$updateAttributes is not a function This issue seems to be affecting all models. I have a hunch that it mig ...

Performing calculations involving both select and checkbox input values, as well as handling negative numbers

Seeking assistance in creating a feature where users can select a billing term from a dropdown and then choose checkboxes to add to the total. While it works fine on JSFIDDLE, I encounter issues on my website - specifically when selecting all checkboxes, r ...

Tips for placing the header text at the center of a TemplateField in your design

I'm using a GridView with TemplateFields. I attempted to align the header text of the TemplateField to center by using HeaderStyle-HorizontalAlign="Center", but it doesn't seem to be working as expected. <asp:TemplateField HeaderTex ...

Combining multiple .php files in a single div

Hey there! I have a piece of code that allows me to load a PHP file into a div. It's currently functional, but I'm facing a challenge where I need to load the next file into the same div. <script type="text/javascript"> $(function() { ...