Struggling to use jasmine/karma to test my class-based controllers, unfortunately without any success. Most examples I come across are dated back to 2014 or older. I've made sure to load the angular and angular-mock files in my karma configuration files. To view the Plunker code, click here: https://plnkr.co/edit/TCXW3rIUqV8OmbzzhDhn?p=catalogue
karma.config.js
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
// List of various files here
],
// other configurations listed here...
})
}
users.spec.js
describe('User component', () => {
let element, scope;
beforeEach(angular.mock.module('MetronicApp'));
// Other setup configurations here...
it('test case here...', () => {
// Test scenario here...
})
});
component
/**
* @name MetronicApp.component:users
*
* @description <users> component, users page displaying all current portal users
*/
class UsersController {
// Controller class implementation here...
}
// Component setup and registration here...
Encountering an error while trying to test this component's method, the updated error message points towards a controller registration issue. The full error details are provided below:
Error: [$controller:ctrlreg] The controller with the name 'UsersController' is not registered.
http://errors.angularjs.org/1.6.7/$controller/ctrlreg?p0=UsersController
// More error details here...
TypeError: Cannot read property 'getFullName' of undefined
// More error details here...