AngularJS-UnitTesting | Weather App | Karma
Hi Experts,
Can you please help me correcting the AngularJS-UnitTesting with Karma
describe('Unit Test', function() { beforeEach(module('ourAppApp')); var $controller;
beforeEach(inject(function($controller){ $controller = $controller; })); describe('Do not remove', function() { it('Check 1', function() { expect(1).toBe(1); }); it('Check 2', function() { expect(1).toBe(1); }); }); });
Below code has the problem:
beforeEach(inject(function($controller){ $controller = $controller; }));
The injected $controller overwrites itself, so nothing is actually assigned.
You can do something like:
beforeEach(inject(function ($controller) { $controller = $controller; }));
Angular strips the underscores and injects the real $controller. This avoids name conflicts with your outer variable.
Since your current tests don’t use it, you can remove it entirely.
Thanks for reaching out! This is a support/debugging question rather than an issue with the style guide itself. For questions like this, Stack Overflow or the Angular community Discord are great places to get help. Closing this to keep the issue tracker focused on the guide content. Hope you found a solution! 🙏