Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Error: Unsatisfied requests: POST http://localhost:5000/google-form
- at Function.$httpBackend.verifyNoOutstandingExpectation
- (.../angular-mocks/angular-mocks.js:1474:13)
- /* global $ */
- 'use strict';
- angular.module('myApp')
- .controller('QuickMessageCtrl', ['$scope', function ($scope) {
- $scope.quickMessageButtonText = 'Send';
- $scope.quickMessage = {
- name: '',
- email: '',
- content: '',
- };
- function setSubmittingIndicators() {
- $scope.quickMessageButtonText = '';
- $scope.submitting = true;
- }
- $scope.postQuickMessageToGoogle = _.throttle(function() {
- setSubmittingIndicators();
- $.ajax({
- url: 'https://docs.google.com/forms/d/MyFormKey/formResponse',
- data: {
- 'entry.3' : $scope.quickMessage.name,
- 'entry.1' : $scope.quickMessage.email,
- 'entry.0' : $scope.quickMessage.content
- },
- type: 'POST',
- dataType: 'jsonp',
- statusCode: {
- 200: function (){
- //show succes message;
- }
- }
- });
- }, 500);
- }]);
- 'use strict';
- describe('Controller: QuickMessageCtrl', function() {
- var $httpBackend, $rootScope, $controller, scope, apiUrl;
- beforeEach(module('myApp'));
- beforeEach(inject(function($injector) {
- $httpBackend = $injector.get('$httpBackend');
- apiUrl = $injector.get('apiUrl');
- $httpBackend.expect(
- 'POST',
- apiUrl + 'google-form',
- {'name': 'test', 'email': 'test@test.com', 'content': 'this is content'}
- ).respond(200);
- $rootScope = $injector.get('$rootScope');
- scope = $rootScope.$new();
- $controller = $injector.get('$controller');
- $controller('QuickMessageCtrl', { $scope: scope });
- }));
- afterEach(function() {
- $httpBackend.verifyNoOutstandingExpectation();
- $httpBackend.verifyNoOutstandingRequest();
- });
- describe('Successful form submit', function() {
- beforeEach(function() {
- scope.quickMessageForm = { $valid: true };
- scope.quickMessage.email = 'test@test.com';
- scope.quickMessage.name = 'test';
- scope.quickMessage.content = 'this is test';
- scope.postQuickMessageToGoogle();
- });
- it('should set submitting indicators on submit', function() {
- expect(scope.quickMessageButtonText).toBe('');
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement