Skip to content

Commit

Permalink
chore: cypress test stabilization
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi committed Feb 15, 2020
1 parent 1313efb commit a61104e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions e2e/cypress/integration/pages/shopping/product-detail.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,22 @@ export class ProductDetailPage {
this.addToCompareButton().click();
}

addProductToCart() {
addProductToCart(): Cypress.Chainable<Cypress.WaitXHR> {
cy.wait(1000);
cy.server()
.route('POST', '**/baskets/*/items')
.as('basket');
cy.server()
.route('GET', '**/baskets/current*')
.as('basketCurrent');
this.addToCartButton().click();
return cy.wait('@basket');

return (
cy
.wait('@basket')
// tslint:disable-next-line: no-any
.then(result => (result.status >= 400 ? result : cy.wait('@basketCurrent').then(() => result))) as any
);
}

addProductToQuoteRequest() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/interceptors/auth.interceptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('Auth Interceptor', () => {
const req2 = httpTestingController.expectOne('some/url');
expect(req2.request.headers.get(ApiService.TOKEN_HEADER_KEY)).toBeFalsy();
req2.flush('some data');
}, 100);
}, 1000);
});

it('should re-throw errors unrelated to tokens', done => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/interceptors/auth.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AuthInterceptor implements HttpInterceptor {
// retry request without auth token
const retryRequest = req.clone({ headers: req.headers.delete(ApiService.TOKEN_HEADER_KEY) });
// timer introduced for testability
return timer(10).pipe(switchMapTo(next.handle(retryRequest)));
return timer(500).pipe(switchMapTo(next.handle(retryRequest)));
}
return throwError(err);
}),
Expand Down

0 comments on commit a61104e

Please sign in to comment.