Skip to content

Instantly share code, notes, and snippets.

@robertklep
Created November 7, 2018 20:08
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 robertklep/595aa56e39c091f87412a41cab5cc866 to your computer and use it in GitHub Desktop.
Save robertklep/595aa56e39c091f87412a41cab5cc866 to your computer and use it in GitHub Desktop.
const assert = require('assert');
function increment(value) {
return new Promise((resolve, reject) => {
if (value < 0) {
reject(Error('I can only increment positive numbers'));
} else {
resolve(value + 1);
}
});
}
describe('increment', () => {
it('should increment the value by 1', () => {
return increment(123).then(value => {
assert.equal(value, 124);
});
});
it('should fail when incrementing negative numbers', () => {
return increment(-123).then(value => {
throw Error('it should have failed');
}, err => {
// swallow the error
});
});
// this test will intentionally fail
it('should not increment the value by 2', () => {
return increment(123).then(value => {
assert.equal(value, 125);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment