Skip to content

Commit

Permalink
Merge pull request #3 from josephshambrook/chore/upgrades
Browse files Browse the repository at this point in the history
Upgrade Cypress and other packages
  • Loading branch information
josephshambrook authored Apr 12, 2021
2 parents 3eac1bd + beab0c9 commit 6dca2fe
Show file tree
Hide file tree
Showing 5 changed files with 34,470 additions and 8,333 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ These functionalities make it possible to test the following in Cypress:
- In a separate Terminal instance, run `npm run cy:open` to open Cypress' UI.
- Alternatively, `npm run cy:run` will run all Cypress tests in one go, with recordings and screenshots

> Note: I recommend using iTerm to run separate Terminal instances in split-screen.
> Note: I recommend using [iTerm](https://iterm2.com/) or [Hyper](https://hyper.is/) to run separate Terminal instances in split-screen.
12 changes: 6 additions & 6 deletions cypress/integration/04-hacker-news.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
describe('Hacker News', () => {
context('API requests slow', () => {
before(() => {});

it('should display the loading title, then replace it with the card', () => {});
});

context('API calls return errors', () => {
it('should display nothing when the topstories URL fails', () => {});

Expand All @@ -18,4 +12,10 @@ describe('Hacker News', () => {

it('displays a link to the post, which opens in a new tab', () => {});
});

context('API requests slow', () => {
before(() => {});

it('should display the loading title, then replace it with the card', () => {});
});
});
78 changes: 40 additions & 38 deletions cypress/integration/cheating/04-hacker-news.spec.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,37 @@
import { TOP_STORIES } from '../../../src/urls';

describe('Hacker News', () => {
context('API requests slow', () => {
before(() => {
cy.server({
delay: 1000,
context('API calls return errors', () => {
it('should display nothing when the topstories URL fails', () => {
cy.intercept(TOP_STORIES, {
statusCode: 404,
body: [],
});
cy.route(TOP_STORIES, 'fixture:topstories.json').as('topstories');
cy.route('**/item/22008566*', 'fixture:item.json').as('item');
cy.visit('/');
});

it('should display the loading title, then replace it with the card', () => {
cy.getTestId('hn-loading').should('be.visible');
cy.getTestId('hn-card').should('not.be.visible');

cy.wait('@item');
cy.getTestId('hn-loading').should('not.be.visible');
cy.getTestId('hn-card').should('be.visible');
cy.getTestId('hn-loading').should('not.exist');
cy.getTestId('hn-card').should('not.exist');
});
});

context('API calls return errors', () => {
it('should display nothing when the topstories URL fails', () => {
cy.server();
cy.route({
url: TOP_STORIES,
status: 404,
response: [],
cy.intercept('**/item/**', {
statusCode: 404,
body: {},
});
cy.reload();
cy.getTestId('hn-loading').should('not.be.visible');
cy.getTestId('hn-card').should('not.be.visible');
});
cy.visit('/');

it('should display nothing when the topstories URL fails', () => {
cy.server();
cy.route({
url: '**/item/**',
status: 404,
response: {},
});
cy.reload();
cy.getTestId('hn-loading').should('not.be.visible');
cy.getTestId('hn-card').should('not.be.visible');
cy.getTestId('hn-loading').should('not.exist');
cy.getTestId('hn-card').should('not.exist');
});
});

context('Card content when API call is successful', () => {
beforeEach(() => {
cy.server();
cy.route(TOP_STORIES, 'fixture:topstories.json').as('topstories');
cy.route('**/item/22008566*', 'fixture:item.json').as('item');
cy.intercept(TOP_STORIES, { fixture: 'topstories.json' }).as(
'topstories'
);
cy.intercept('**/item/22008566*', { fixture: 'item.json' }).as('item');

cy.visit('/');
cy.wait('@topstories');
});
Expand All @@ -72,4 +52,26 @@ describe('Hacker News', () => {
);
});
});

context('API requests slow', () => {
before(() => {
cy.intercept(TOP_STORIES, { fixture: 'topstories.json', delay: 2000 }).as(
'topstories'
);
cy.intercept('**/item/22008566*', {
fixture: 'item.json',
delay: 2000,
}).as('item');
cy.visit('/');
});

it('should display the loading title, then replace it with the card', () => {
cy.getTestId('hn-loading').should('be.visible');
cy.getTestId('hn-card').should('not.exist');

cy.wait('@item');
cy.getTestId('hn-loading').should('not.exist');
cy.getTestId('hn-card').should('be.visible');
});
});
});
Loading

0 comments on commit 6dca2fe

Please sign in to comment.