Created
September 9, 2019 23:34
-
-
Save brittanmcg/24307fcd1684a1bca15233f73e9b8fc9 to your computer and use it in GitHub Desktop.
test example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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