Skip to content

Commit

Permalink
Switch to reqres as jsonplaceholder is down
Browse files Browse the repository at this point in the history
  • Loading branch information
mhssmnn committed Jul 11, 2022
1 parent 6950f03 commit f4a645a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/fixture.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('setup', function () {
cy.readFile('../mocks/fixture.spec.json').should('not.exist');
cy.readFile('../fixtures/fixture-spec').should('not.exist');
// Ensure the http request has finished
cy.contains(/"userId":1/i);
cy.contains(/"id":1/i);
});
});

Expand Down
10 changes: 1 addition & 9 deletions cypress/integration/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ <h1>cypress-autorecord</h1>
</div>
</main>
<script>
// var oReq = new XMLHttpRequest();
// oReq.addEventListener('load', function () {
// var json = JSON.parse(this.responseText);
// document.getElementById('json').innerText = JSON.stringify(json);
// });
// oReq.open('GET', 'https://jsonplaceholder.typicode.com/todos/1');
// oReq.send();

fetch('https://jsonplaceholder.typicode.com/todos/1')
fetch('https://reqres.in/api/users/1')
.then((response) => response.json())
.then((json) => {
document.getElementById('json').innerText = JSON.stringify(json);
Expand Down
17 changes: 14 additions & 3 deletions cypress/integration/spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
const autoRecord = require('../../index');
const testName = 'records a mock after the test has finished';

// Ensures the next test doesn't load fixtures before they're
// deleted!
describe('beforeSetup', function () {
beforeEach(function () {
cy.task('removeAllMocks');
});

it('deletes the mocks', function () {
cy.readFile('../mocks/spec.json').should('not.exist');
});
});

describe('setup', function () {
autoRecord();

beforeEach(function () {
cy.task('removeAllMocks');
cy.visit('cypress/integration/index.html');
});

it(testName, function () {
cy.readFile('../mocks/spec.json').should('not.exist');
// Ensure the http request has finished
cy.contains(/"userId":1/i);
cy.contains(/"id":1/i);
});
});

Expand All @@ -25,7 +36,7 @@ describe('test', function () {
const { routes } = mock[testName];
const [{ response }] = routes;

expect(response).to.include({ userId: 1, id: 1 });
expect(response.data).to.include({ id: 1 });
});
});
});
Expand Down

0 comments on commit f4a645a

Please sign in to comment.