Getting method as undefined while running karma test

I have created a scope method inside my controller which is executing when a button is pressed. I am writing unit test cases for the same. I have injected my module in beforeEach block and created spyon my scope function and then using it in ‘it’ method and checking whether it is called or not. But getting an error as a method not found.

Controller

    'use strict';

angular.module('myApp.view1', ['ngRoute'])

  .config(['$routeProvider', function ($routeProvider) {
    $routeProvider.when('/view1', {
      templateUrl: 'view1/view1.html',
      controller: 'View1Ctrl'
    });
  }])

  .controller('View1Ctrl', ['$scope',View1Ctrl])

  function View1Ctrl($scope) {
    $scope.user = {
      name: '',
      last: ''
    }
    $scope.showFormData = function() {
      $scope.formData = $scope.user.name + $scope.user.last;
    }
  }

spec.js

   'use strict';

describe('myApp.view1 module', function () {

  var $controller, $rootScope;
  beforeEach(module('myApp.view1'));

  beforeEach(inject(function (_$controller_, _$rootScope_) {
    $controller = _$controller_;
    $rootScope = _$rootScope_;
  }));

  describe('view1 controller', function () {

    var $scope, controller, formData;
    beforeEach(function () {
      $scope = $rootScope.$new();
      controller = $controller('View1Ctrl', {
        $scope: $scope
      });
      spyOn(controller, 'showFormData');
    });

    it('should check for the show form details', function () {
      $scope.user.name = "Sandeep";
      $scope.user.last = "Gupta";
      expect($scope.showFormData).toHaveBeenCalled();
      expect($scope.user.name + $scope.user.last).toEqual(firstname);
    });

  });
});

Need help to resolve this issue.

Source: AngularJS