Tuesday, June 4, 2024
124
rated 0 times [  131] [ 7]  / answers: 1 / hits: 23604  / 12 Years ago, fri, january 25, 2013, 12:00:00

I'm actually new to JavaScript as well as Jasmine. So it might be something really obvious that fixes my problem but I can't see it.



I want to check if (an already existing) JavaScript application calls console.error() while loading. I don't really see a way how to realise this with Jasmine. I've included the JavaScript file as well as the spec file in the SpecRunner.html.
But I take it that I somehow need to instantiate the application in order to test if it throws any errors on the console, right?



Or should I include the SpecRunner.html code only for this purpose into the HTML code of the app?


More From » unit-testing

 Answers
59

You can spy on console.error like this:



beforeEach(function(){
spyOn(console, 'error');
})

it('should print error to console', function(){
yourApp.start();
expect(console.error).toHaveBeenCalled();
})

[#80630] Wednesday, January 23, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
krystadesiraeo

Total Points: 493
Total Questions: 93
Total Answers: 100

Location: San Marino
Member since Thu, Jun 30, 2022
2 Years ago
;