angular-styleguide icon indicating copy to clipboard operation
angular-styleguide copied to clipboard

AngularJS-UnitTesting | Weather App | Karma

Open sahilgupta3 opened this issue 6 years ago • 2 comments

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); }); }); });

sahilgupta3 avatar Jun 09 '20 17:06 sahilgupta3

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.

kartik1211 avatar Jan 07 '26 03:01 kartik1211

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! 🙏

johnpapa avatar Apr 30 '26 18:04 johnpapa