Created
February 7, 2018 03:37
-
-
Save d-ash/909ba412349e27a9a33ce0bccde2f2fc to your computer and use it in GitHub Desktop.
Testing a logic that returns a promise
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 createPromise = (successful, arg) => { | |
return new Promise((resolve, reject) => { | |
successful ? resolve(arg) : reject(arg); | |
}); | |
}; | |
describe('Testing a promise', () => { | |
describe('Returning a Promise', () => { | |
it('calls the resolve callback', () => { | |
expect.assertions(1); | |
return createPromise(true, 'ARG') | |
.then((arg) => { expect(arg).toBe('ARG'); } ); | |
}); | |
it('calls the reject callback', () => { | |
expect.assertions(1); | |
return createPromise(false, 'ARG') | |
.catch((arg) => { expect(arg).toBe('ARG'); }); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment