Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Vializ committed May 4, 2017
1 parent 5f3f999 commit d2f3150
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions extensions/amp-form/0.1/amp-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export class AmpForm {

/**
* Transition the form to the submit success state.
* @param {../../../src/service/xhr-impl.FetchResponse} response
* @param {!../../../src/service/xhr-impl.FetchResponse} response
* @return {!Promise}
* @private
*/
Expand Down Expand Up @@ -542,7 +542,7 @@ export class AmpForm {

/**
* Handles response redirect throught the AMP-Redirect-To response header.
* @param {../../../src/service/xhr-impl.FetchResponse} response
* @param {!../../../src/service/xhr-impl.FetchResponse} response
* @private
*/
maybeHandleRedirect_(response) {
Expand Down
21 changes: 12 additions & 9 deletions extensions/amp-form/0.1/test/test-amp-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ import {
CONFIG_KEY,
} from '../form-verifiers';
import * as sinon from 'sinon';
import {timerFor} from '../../../../src/services';
import '../../../amp-mustache/0.1/amp-mustache';
import {actionServiceForDoc} from '../../../../src/services';
import {
cidServiceForDocForTesting,
} from '../../../../extensions/amp-analytics/0.1/cid-impl';
import {documentInfoForDoc} from '../../../../src/services';
import {
actionServiceForDoc,
documentInfoForDoc,
timerFor,
} from '../../../../src/services';
import {FetchError} from '../../../../src/service/xhr-impl';
import '../../../amp-selector/0.1/amp-selector';

describes.repeated('', {
Expand Down Expand Up @@ -505,8 +508,10 @@ describes.repeated('', {
errorContainer.appendChild(errorTemplate);
let renderedTemplate = document.createElement('div');
renderedTemplate.innerText = 'Error: hello there';
sandbox.stub(ampForm.xhr_, 'fetch')
.returns(Promise.reject({responseJson: {message: 'hello there'}}));
sandbox.stub(ampForm.xhr_, 'fetch').returns(Promise.reject({
response: {},
responseJson: {message: 'hello there'},
}));
sandbox.stub(ampForm.templates_, 'findAndRenderTemplate')
.returns(Promise.resolve(renderedTemplate));
const event = {
Expand Down Expand Up @@ -1477,10 +1482,8 @@ describes.repeated('', {
json: () => Promise.resolve(),
headers: headersMock,
});
const fetchRejectPromise = Promise.reject({
responseJson: null,
headers: headersMock,
});
const fetchRejectPromise = Promise.reject(
new FetchError('Error', {headers: headersMock}));
fetchRejectPromise.catch(() => {
// Just avoiding a global uncaught promise exception.
});
Expand Down
6 changes: 3 additions & 3 deletions src/service/xhr-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ export class FetchError extends AbstractError {
/**
* @param {string} message
* @param {!FetchResponse} response
* @param {boolean} retriable
* @param {boolean=} opt_retriable
* @param {?JSONType=} opt_responseJson
*/
constructor(message, response, retriable, opt_responseJson) {
constructor(message, response, opt_retriable, opt_responseJson) {
super(message);
this.response = response;
this.retriable = retriable;
this.retriable = opt_retriable;
this.responseJson = opt_responseJson;
}
}
Expand Down

0 comments on commit d2f3150

Please sign in to comment.