Skip to content

Commit

Permalink
Alternative to using fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
Walmyr Filho committed Sep 13, 2021
1 parent b1ba3fc commit f8925db
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 178 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.DS_Store
cypress.env.json
cypress/fixtures/stories.json
cypress/screenshots/
cypress/videos/
node_modules/
1 change: 1 addition & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"baseUrl": "https://wlsf82-hacker-stories.web.app/",
"fixturesFolder": false,
"pluginsFile": false
}
164 changes: 0 additions & 164 deletions cypress/fixtures/example.json

This file was deleted.

18 changes: 9 additions & 9 deletions cypress/integration/hackerStories.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
describe('Hacker Stories', () => {
beforeEach(() => {
cy.generateFixture()
cy.generateNStories(20).then(stories => {
cy.intercept(
'GET',
'**/search?query=React&page=0',
{ body: stories }
).as('getStories')

cy.intercept(
'GET',
'**/search?query=React&page=0',
{ fixture: 'stories' }
).as('getStories')

cy.visit('/')
cy.wait('@getStories')
cy.visit('/')
cy.wait('@getStories')
})
})
it('renders 20 stories, then 19 when dismissing one', () => {
cy.get('.item').should('have.length', 20)
Expand Down
8 changes: 4 additions & 4 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Cypress.Commands.add('generateFixture', () => {
Cypress.Commands.add('generateNStories', n => {
const faker = require('faker')

cy.writeFile('cypress/fixtures/stories.json', {
'hits': Cypress._.times(20, () => {
return {
'hits': Cypress._.times(n, () => {
return {
'title': `${faker.lorem.words(3)}`,
'url': `${faker.internet.url()}`,
Expand All @@ -12,5 +12,5 @@ Cypress.Commands.add('generateFixture', () => {
'objectID': `${faker.datatype.uuid()}`,
}
})
})
}
})

0 comments on commit f8925db

Please sign in to comment.