Let's delve into a scenario using Angular JS/ES6/Jasmine with the Controller 'as' syntax.
Here is the code snippet:
Controller.toggleWidgetView = () => {
Controller.isFullScreenElement() ? Controller.goNormalScreen() : Controller.goFullScreen();
};
We have set up some test cases in Jasmine to ensure functionality:
describe('.toggleWidgetView()', function() {
it('should invoke goNormalScreen method', function() {
spyOn(Controller, 'isFullScreenElement').and.callFake(function(){
return true;
});
spyOn(Controller, 'goNormalScreen').and.callThrough();
Controller.toggleWidgetView();
expect(Controller.goNormalScreen).toHaveBeenCalled();
});
it('should call goFullScreen method', function() {
spyOn(Controller, 'isFullScreenElement').and.callFake(function(){
return false;
});
spyOn(Controller, 'goFullScreen').and.callThrough();
Controller.toggleWidgetView();
expect(Controller.goFullScreen).toHaveBeenCalled();
});
});
Both test cases have been successfully passed.
The essence of these tests lies in invoking the 'toggleWidgetView' method twice, each time altering the condition (true/false) to mimic real-world scenarios.