Skip to content

Instantly share code, notes, and snippets.

@d-ash
Created February 7, 2018 03:37
Show Gist options
  • Save d-ash/909ba412349e27a9a33ce0bccde2f2fc to your computer and use it in GitHub Desktop.
Save d-ash/909ba412349e27a9a33ce0bccde2f2fc to your computer and use it in GitHub Desktop.
Testing a logic that returns a promise
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