Skip to content

Commit

Permalink
test(Interceptor): Add tests checking mocks do not work if they are d…
Browse files Browse the repository at this point in the history
…isabled or the master toggle is
  • Loading branch information
morsdyce committed Jun 9, 2018
1 parent 91b1337 commit 215aee4
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
40 changes: 40 additions & 0 deletions integration-tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ <h3>Web worker request</h3>
<button id="webworker-get-xhr">Get XHR</button>
</div>

<div>
<h3>Disabled mock request</h3>
<button id="disabled-get-fetch">Get FETCH</button>
<button id="disabled-get-xhr">Get XHR</button>
</div>

<div>
<h3>Master toggle off request</h3>
<button id="master-get-fetch">Get FETCH</button>
<button id="master-get-xhr">Get XHR</button>
</div>

<h3>Result</h3>
<div id="result"></div>

Expand Down Expand Up @@ -214,6 +226,34 @@ <h3>Result</h3>
requestMethod: 'xhr'
});
});

$('#disabled-get-xhr').click(function() {
clearResponse();
$.get('http://mimic-example.com/get')
.then(outputResponse)
.fail(outputError);
});

$('#disabled-get-fetch').click(function() {
clearResponse();
$.get('http://mimic-example.com/get')
.then(outputResponse)
.fail(outputError);
});

$('#master-get-xhr').click(function() {
clearResponse();
$.get('http://mimic-example.com/get')
.then(outputResponse)
.fail(outputError);
});

$('#master-get-fetch').click(function() {
clearResponse();
$.get('http://mimic-example.com/get')
.then(outputResponse)
.fail(outputError);
});
</script>
</body>
</html>
56 changes: 56 additions & 0 deletions test/integration/interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,60 @@ module.exports = {
.assert.containsText('#result', '"FETCH-WORKER"')
.end();
},

'No response when mock is disabled - XHR' : function(browser) {
browser
.url('http://127.0.0.1:8080/integration-tests')
.execute(function(data) {
window.mimic.api.import('{"version":"2.0.0","groups": [],"mocks":[{"id":"1e4cef8d-5724-4e9b-812c-4ed260107194","active":false,"method":"GET","url":"http://mimic-example.com/get","headers":{"pragma":"no-cache","content-type":"text/plain; charset=utf-8","cache-control":"no-cache","expires":-1},"params":"","response":{"delay":20,"status":200,"body":"GET-FETCH"}}]}');
})
.waitForElementVisible('#disabled-get-xhr', 1000)
.click('#disabled-get-xhr')
.pause(500)
.assert.containsText('#result', 'request failed')
.end();
},

'No response when mock is disabled - fetch' : function(browser) {
browser
.url('http://127.0.0.1:8080/integration-tests')
.execute(function(data) {
window.mimic.api.import('{"version":"2.0.0","groups": [],"mocks":[{"id":"1e4cef8d-5724-4e9b-812c-4ed260107194","active":false,"method":"GET","url":"http://mimic-example.com/get","headers":{"pragma":"no-cache","content-type":"text/plain; charset=utf-8","cache-control":"no-cache","expires":-1},"params":"","response":{"delay":20,"status":200,"body":"GET-FETCH"}}]}');
})
.waitForElementVisible('#disabled-get-fetch', 1000)
.click('#disabled-get-fetch')
.pause(500)
.assert.containsText('#result', 'request failed')
.end();
},

'No response when master toggle is off - XHR' : function(browser) {
browser
.url('http://127.0.0.1:8080/integration-tests')
.execute(function(data) {
window.mimic.api.import('{"version":"2.0.0","groups": [],"mocks":[{"id":"1e4cef8d-5724-4e9b-812c-4ed260107194","active":true,"method":"GET","url":"http://mimic-example.com/get","headers":{"pragma":"no-cache","content-type":"text/plain; charset=utf-8","cache-control":"no-cache","expires":-1},"params":"","response":{"delay":20,"status":200,"body":"GET-FETCH"}}]}');
// disable mimic via master toggle
window.mimic.api.turnOff();
})
.waitForElementVisible('#master-get-xhr', 1000)
.click('#master-get-xhr')
.pause(500)
.assert.containsText('#result', 'request failed')
.end();
},

'No response when master toggle is off - fetch' : function(browser) {
browser
.url('http://127.0.0.1:8080/integration-tests')
.execute(function(data) {
window.mimic.api.import('{"version":"2.0.0","groups": [],"mocks":[{"id":"1e4cef8d-5724-4e9b-812c-4ed260107194","active":true,"method":"GET","url":"http://mimic-example.com/get","headers":{"pragma":"no-cache","content-type":"text/plain; charset=utf-8","cache-control":"no-cache","expires":-1},"params":"","response":{"delay":20,"status":200,"body":"GET-FETCH"}}]}');
// disable mimic via master toggle
window.mimic.api.turnOff();
})
.waitForElementVisible('#master-get-fetch', 1000)
.click('#master-get-fetch')
.pause(500)
.assert.containsText('#result', 'request failed')
.end();
}
};

0 comments on commit 215aee4

Please sign in to comment.