Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- httpBackend.whenPOST('/myurl')
- .respond( 200,obj1 );
- httpBackend.expectPOST('/myurl')
- scope = $rootScope.$new();
- MainCtrl = $controller('MyCtrl', {
- $scope:scope
- });
- it('scope.mymethod should work fine', function(){
- httpBackend.flush()
- // verify size of array before calling the method
- expect(scope.myobjs.length).toEqual(2)
- // call the method
- scope.saveNewPage(myobj)
- // verify size of array after calling the method
- expect(scope.myobjs.length).toEqual(3)
- })
- function saveNewPage(p){
- console.log('Hello')
- $http.post('/myurl', {
- e:p.e, url:p.url, name:p.name
- }).then(function (response) {
- otherMethod(new Page(response.data.page))
- }, handleError);
- }
- it('scope.saveNewPage should work fine', function(){
- var p=new Object(pages[0])
- httpBackend.flush()
- httpBackend.whenPOST('/myurl',{
- url:pages[0].url,
- existingPage:new Object(pages[0]),
- name:pages[0].name
- }).respond(200,{data:pages[0]})
- httpBackend.expectPOST('/myurl')
- scope.saveNewPage(p)
- httpBackend.flush()
- expect(scope.pages.length).toBe(3)
- })
- it('scope.mymethod should work fine', function(){
- expect(scope.myobjs.length).toEqual(2)
- scope.saveNewPage(myobj)
- expect(scope.myobjs.length).toEqual(2)
- httpBackend.flush()
- expect(scope.myobjs.length).toEqual(3)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement