Single Page Web Applications with AngularJS Week 5 Quiz

Course Name: Single Page Web Applications with AngularJS

Course Link: Single Page Web Applications with AngularJS

These are Single Page Web Applications with AngularJS Week 5 Quiz Answers


Quiz 41

Question 1
What is missing in the following snippet of code in order to make sure AngularJS is in charge of validating this form?

<form name='formName'>
  <input
   type="text"
   name="firstName"
   ng-model="ctrl.firstName"
   required
   min-length="10">
   <button ng-click="ctrl.validate()"></button>
</form>

Button has to have ng-model defined on it
form element is missing ‘novalidate’ attribute.
The required attribute should be required=”true”

Answer: form element is missing ‘novalidate’ attribute.


These are Single Page Web Applications with AngularJS Week 5 Quiz Answers


Question 2
Given the following HTML snippet:

<form name='formName'>
  <input
   type="text"
   name="firstName"
   ng-model="ctrl.firstName"
   required>

   <span ng-if="formName.firstName.$error.required && formName.firstName.$touched">Name is required</span>

   <button ng-click="ctrl.validate()"></button>
</form>

When is the error message “Name is required” going to be displayed?
When the form is first displayed to the user if the textbox is empty.
When the user hovers over the textbox if it’s is empty.
When the user clicks into the textbox and then clicks somewhere else, leaving the textbox empty.
When the user clicks into the empty textbox.

Answer: When the user clicks into the textbox and then clicks somewhere else, leaving the textbox empty.


These are Single Page Web Applications with AngularJS Week 5 Quiz Answers


Quiz 42

Question 1
When speaking of testing your code, “mocking” refers to

Teasing other developers who don’t test their code. 😜
Developer or library creating objects that can serve as substitutes for real services that the test is not testing, but the target code relies on.
Importing needed libraries for the test to run
I have no idea, but isn’t the proper term Mac-ing as in using a Mac computer?

See also  Single Page Web Applications with AngularJS Week 3 Quiz

Answer: Developer or library creating objects that can serve as substitutes for real services that the test is not testing, but the target code relies on.


Question 2
The function beforeEach is run one time per “describe” function block.

True
False

Answer: False


These are Single Page Web Applications with AngularJS Week 5 Quiz Answers


Quiz 43

Question 1
Using ‘inject’ function in the ‘beforeEach’ method, what is function’s full name?

Mr. In Ject
angular.inject
angular.mock.inject

Answer: angular.mock.inject


Question 2
What does the $controller do?

It’s a custom service you can create for testing.
It’s an Angular testing service that tests controllers in our application.
It’s a standard service that AngularJS uses to instantiate controllers in our applications. We can use it ourselves to instantiate the controller we are testing manually.

Answer: It’s a standard service that AngularJS uses to instantiate controllers in our applications. We can use it ourselves to instantiate the controller we are testing manually.


These are Single Page Web Applications with AngularJS Week 5 Quiz Answers


Quiz 44

Question 1
What does the following line do?

var myService = $injector.get('MyService');

Defines a service called ‘MyService’
Injects the existing service called ‘MyService’
Retrieves an existing service called ‘MyService’.

Answer: Retrieves an existing service called ‘MyService’.


Question 2
What is the name of the service AngularJS provides for simulating network calls?

$httpMock
$http
$httpBackend

Answer: $httpBackend


These are Single Page Web Applications with AngularJS Week 5 Quiz Answers


Question 3
What method needs to be called at the end of every test that uses $httpBackend service to simulate network calls?

$httpBackend.whenGET
$httpBackend.flush
$httpBackend.whenDone

See also  Single Page Web Applications with AngularJS Week 1 Quiz

Answer: $httpBackend.flush


Quiz 45

Question 1
What service can we use to avoid having the directive reach out over the network to retrieve the resource declared with templateUrl?

$httpBackend
$templateUrlService
$templateCache

Answer: $templateCache


These are Single Page Web Applications with AngularJS Week 5 Quiz Answers


Question 2
What does the $compile service return? For example, what is contained in the ‘x’ variable after the following statement:

var x = $compile(html);

Byte code.
A function value that expects some scope as an argument such that it can use that scope to bind the data to the “compiled” HTML.
$scope

Answer: A function value that expects some scope as an argument such that it can use that scope to bind the data to the “compiled” HTML.


Question 3
What must be called in order to have the bound data update the view (i.e, output of the directive)?

$compile(html)($rootScope)
The $digest() as in $rootScope.$digest()
$config.run

Answer: The $digest() as in $rootScope.$digest()


These are Single Page Web Applications with AngularJS Week 5 Quiz Answers


Quiz 46

Question 1
What service do we use to create the controller in a test environment for our component?

$component
The standard AngularJS $componentController
The ngMock module’s $componentController

Answer: The ngMock module’s $componentController


These are Single Page Web Applications with AngularJS Week 5 Quiz Answers


Quiz 47

Question 1
What would happen if we skipped the following line of code in the ‘responseError’ function of the interceptor?

return $q.reject(response);

It’s just a precaution. It’s not really needed here.
The call will still return to the caller and it will look like our promise ‘resolved’ when it fact, the promise failed. The caller code will treat the response object as if it’s the expected result which will probably cause errors.
Everything will resolve successfully.
The HTTP call will fail and throw errors.

See also  Single Page Web Applications with AngularJS Week 4 Quiz

Answer: The call will still return to the caller and it will look like our promise ‘resolved’ when it fact, the promise failed. The caller code will treat the response object as if it’s the expected result which will probably cause errors.


These are Single Page Web Applications with AngularJS Week 5 Quiz Answers


More Weeks of the course: Click Here

More Coursera courses: https://progiez.com/coursera

Single Page Web Applications with AngularJS Week 5 Quiz