Skip to content

Instantly share code, notes, and snippets.

@brittanmcg
Created September 9, 2019 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brittanmcg/24307fcd1684a1bca15233f73e9b8fc9 to your computer and use it in GitHub Desktop.
Save brittanmcg/24307fcd1684a1bca15233f73e9b8fc9 to your computer and use it in GitHub Desktop.
test example
const writeToS3 = (data) => {
console.info('writing to S3');
fetch('s3Url', {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json',
}
})
}
const postDataSomewhere = (data) => {
writeToS3(moreData); // spy successfully
fetch(data.url, {
method: 'POST',
body: JSON.stringify(data.body),
headers: {
'Content-Type': 'application/json',
}
}).then((moreData) => {
writeToS3(moreData); // cannot spy on this
})
}
/** Jasmine Tests Jasmine 3.4.0 */
describe('tests', () => {
beforeEach(() => {
s3spy = spyOn(writeToS3).and.callFake(function() {
console.info("DELEGATED TO SPY ON WRITETOS3")
});
})
it('should call things with correct stuff', (done) => {
postDataSomewhere()
expect(s3spy).toHaveBeenCalledTimes(2)
done();
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment