In a project based on angular-seed project, I am running unit tests with ./scripts/test.sh --log-level debug
but none of the log messages that I see are coming from my app. How do I get to see them? In my app, I am logging with $log
.
Load the Angular App beforeEach(module('MyApp')); //3. Describe the object by name describe('compute', function () { var compute; //4. Initialize the filter beforeEach(inject(function ($filter) { compute = $filter('compute', {}); })); //5. Write the test in the it block along with expectations.
AngularJS includes a logging service called $log, which logs the messages to the client browser's console. The $log service includes different methods to handle the log for error, information, warning or debug information. It can be useful in debugging and auditing.
Thanks. As mentioned, tests can inject console
for $log
using $provide
. For posterity, $provide
is not available via inject(function(...) { ... })
but instead must be injected into a function argument to module
:
beforeEach(module('myapp', function($provide) {
// Output messages
$provide.value('$log', console);
}));
Got it working! Had I used console.log
directly it would have worked but now that I am using $log
I had to patch it in a beforeEach
(looks like by default it wasn't wired by angularjs):
$provide.value('$log', console);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With