The controller in AngularJS seems to be elusive and cannot be located

I've run into an issue while using angular-mock to inject my controller for unit testing. The error message I keep receiving is as follows:

 [$injector:unpr] Unknown provider: PatientRecordsControllerProvider <- PatientRecordsController

This is how my code is set up -

    (function () {
angular.module('patient_profile', ['ngRoute']);
    })();


(function () {
    var PatientRecordsController = function () {

    };

    angular.module('patient_profile').controller('PatientRecordsController', PatientRecordsController);
})();

Below is my test case snippet

    describe('Unit Testing on PatientRecordsController', function () {

    beforeEach(module('patient_profile'));

    it('timeline should be an array', inject(['PatientRecordsController',
        function (controller) {
            //Unable to perform operations
        }
    ]));

});

LATEST UPDATE: Interestingly, the method works flawlessly with services. Why is that?

Answer №1

To properly instantiate the Controller, use the $controller service. Do you think the following test format is more organized?

describe('PatientRecordsController:unit-testing', function () {
    var controller;

    beforeEach(function(){
        module('patient_profile');

        inject(function(_$controller_){
            controller = _$controller_('PatientRecordsController', {});
        });
    });

    it('timeline should be an array', function(){
        //Perform actions using the controller
    });
});

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

JavaScript - Transferring Files across Folders

I manage three folders: 'Received', 'Successful', and 'Error'. When a new file is added to the 'Received' folder, my system processes it. Successfully processed files are moved to the 'Successful' folder, w ...

Transferring information from socket.io to vue.js

I am currently facing an issue with passing socket.io data to a Vue.js element. Despite going through the Vue documentation multiple times, I have not been able to find a solution. The data is being sent to the client via socket.io and successfully logged ...

Analyzing data visualization within CSS styling

I have the desire to create something similar to this, but I am unsure of where to start. Although I have a concept in mind, I am struggling to make it functional and visually appealing. <div id="data"> <div id="men" class="shape"></di ...

Ways to imitate typeORM repository

Looking for some guidance on writing tests and mocking the typeORM repository. I've tried a few approaches, but couldn't quite figure it out, particularly with the @InjectRepository method. Any suggestions? import { AfterRoutesInit, Service } fr ...

Including onMouseUp and onMouseDown events within a JavaScript function

I am experiencing an issue with a div that contains an input image with the ID of "Area-Light". I am attempting to pass the ID of the input image to a function. Although event handlers can be directly added inside the input tag, I prefer to do it within ...

NPM rimraf - proceed with the execution even if directories are not found (do not halt with exit code 1)

My npm script is set up to run a series of synchronous commands, starting with npm run clean:install". Here is the sequence: "install:all": "npm install && bower install", "clean": "npm run rimraf -- node_modules doc typings coverage wwwroot bow ...

What is the best way to remove excess content that falls outside the viewBox?

Is there a function or method to trim a path that extends beyond the viewbox rather than simply concealing it? I am currently using svg-edit, which has a specific viewbox or canvas area. Any elements drawn outside of this canvas remain hidden. However, wh ...

Reset the text input field when the dropdown menu is set to 'no/other'

CURRENT: Choosing from a dropdown menu with options 'Yes' or 'No'. If 'Yes' is chosen: Display additional dropdowns/inputs for entry If 'No' is chosen: Conceal additional dropdowns/inputs WANT: I am looking to imp ...

The ES6 method of binding click handlers with parameters in React

After reading numerous articles on the usage of () => {} syntax, binding in the constructor, and binding in the props, I have come to understand that binding this can be performance-intensive. Furthermore, automatic binding with arrow functions incurs a ...

Unable to invoke angular ng-click function using jQuery

Can someone assist me in calling ng-click from jQuery correctly? I am having trouble getting it to work. Any guidance on the proper way to do this would be greatly appreciated. HTML: <a ng-click="changeData()">Testing</a> <a ng-click="chan ...

Anticipating the completion of multiple observable subscription functions

Is there a way to replace and convert all words in an array using an object's method that returns an observable? I found a helpful solution on this post which uses bind to pass the correct value. After all subscriptions are complete, I want to execut ...

How can I use nodejs to retrieve all data fields from a table except for one specific field?

Is there a way to fetch all fields data from a table without specifying the field names or creating a view? I have attempted the following SQL query: WITH orderschema as (SELECT array_to_string(ARRAY(SELECT c.column_name FROM information_schema.co ...

Encountering a problem with configuring webpack's CommonsChunkPlugin for multiple entry points

entry: { page1: '~/page1', page2: '~/page2', page3: '~/page3', lib: ['date-fns', 'lodash'], vendor: ['vue', 'vuex', 'vue-router'] }, new webpack.optimize.C ...

Skip nodes in Polymer 1.0 by using ExcludeLocalNames

I recently attempted to transition from Polymer version 0.5 to 1.0 and came across a particular question: Is there a way to exclude certain nodes inside a paper-menu? In the previous version (0.5), you could use the attribute excludedLocalNames to achieve ...

Using array index to group colors in Javascript

Below is an array that I have: const colors = ['#54AAED', '#7BEA6B', '#f8b653', '#ff5584'] I am working on creating a function that can return a color based on the parameter group and index. For example: function ...

Using Multiple Submit Buttons in an HTML form with Express.js and Node.js

I'm currently implementing a like/dislike feature with two buttons on the HTML side. <form method="post" name="ratings"> <input type="submit" name="vote" value="like"> <input type="submit" name="vote" value="dislike"> </f ...

How come I am getting only a single outcome when iterating through a dataset array?

I have a fetch API that returns an array of objects, and within those objects are nested arrays and other objects. My goal is to filter out only the objects that contain a specific value. Specifically, I want to retrieve objects with an id of 11 from the p ...

Enabling table row scrolling with keyboard navigation in React

Struggling to figure out how to make my table scroll while navigating through the rows using the onKeyDown event. It seems that the event isn't updating when using the keyboard, even though the highlighting of the selected row with selected is working ...

Synchronizing the scrolling of two elements with varying heights: A guide

There are two DIV elements in question: #page and #block : <div id="page"></div> <div id="block"></div> The #block element has a fixed position and contains long content with the property overflow:hidden. The #page element also c ...

.slideDown Not Functioning Properly on my System

After successfully linking my index.html file to jQuery, I am facing an issue with the .slideDown code. I'm not sure if there is a problem with the code itself or if I didn't attach jQuery correctly. Can anyone help me troubleshoot this? Below i ...