dimanche 28 juin 2015

How to unit test $http in angularjs and Jasmine

Here is my code, I've made a Plunker as the code is long:

 describe("create", function(){
        it("Should be defined", function(){
            expect(BaseService.create).toBeDefined();
        });

        it("it should POST to http://ift.tt/1TZoju1", function(){

          /***
           * 
           * NOT TO SURE WHAT TO DO HERE
           * 
           */

        })
    });

http://ift.tt/1edSHzM

I am new to Unit Testing so I am having a bit of trouble working out how to assert the following:

  1. If the method is going to x url
  2. If the method is using x method (e.g. GET, PUT, POST or DELETE)
  3. If the data passed to the method is the same as the data that is sent in the call
  4. If the return type of the method is a Promise
  5. If the contents of the Promise matches the expected type.

On a side note I am also open to suggestions for things I should also test.

Aucun commentaire:

Enregistrer un commentaire