Skip to main content

Posts

Showing posts from February, 2017

Mock HTTP calls with Angular and Protractor

One of the benefits using AngularJS is also using some test tools like Protractor. Protractor is a tool that was made for Angular testing. Many times when testing you will need to mock some data so that you can see if your application responds in the correct manner. Let us assume that we have the following HTML file running our application.
<!doctype html> <html ng-app="demo"> <head> <title>Hello</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-mocks.js"></script> <script src="hello.js"></script> </head> <body> <div ng-controller="Hello"> <p>Hello <span id="gname">{{exampleResponse.name}}</span></p> </div> …

Build your own expectation library.

In the world of impending deadlines, testing is a key a vital role with any project. When building software you can test many functions and processes in a matter of minutes depending on how you setup your tests and how well the code was written to be testable. A key element for that tests is what you expect. Javascript for example, there are many expectation frameworks out there. Jasmine, Chai, Mocha to name a few. Let's build a simple expectation without their input. var expect = function(obj) { return {} } This will be our starting point for what we will expect. Very simply it is a function that will accept an argument obj and then it returns some object back that will be defined in more detail soon. You may be thinking one object? That doesn't seem quite right. For an expect statement to work shouldn't we have something like "expect(a, b, 'equal')". Yes, we could do something like that. However, for this example, we will attempt to make the co…