Skip to content

Commit

Permalink
Add "to start with" as an alias for "to begin with".
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjeffburke committed Jul 1, 2018
1 parent 4986d6a commit dcbea8e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/assertions.js
Expand Up @@ -687,7 +687,10 @@ module.exports = expect => {
});

expect.addAssertion(
'<string> [not] to begin with <string>',
[
'<string> [not] to begin with <string>',
'<string> [not] to start with <string>'
],
(expect, subject, value) => {
if (value === '') {
throw new Error(
Expand Down
44 changes: 44 additions & 0 deletions test/assertions/to-start-with.spec.js
@@ -0,0 +1,44 @@
/*global expect*/
describe('to start with assertion', function() {
it('should throw an error when the expected prefix is the empty string', function() {
expect(
function() {
expect('foo', 'to start with', '');
},
'to throw',
"The 'to start with' assertion does not support a prefix of the empty string"
);
});

describe('without the "not" flag', function() {
it('asserts equality with a string', function() {
expect('hello', 'to start with', 'hello');
expect('hello world', 'to start with', 'hello');
});
});

describe('when the assertion fails', function() {
it('does not include a diff when there is no common prefix', function() {
expect(
function() {
expect('hello world', 'to start with', 'foo');
},
'to throw exception',
"expected 'hello world' to start with 'foo'"
);
});

it('includes a diff when there is a common prefix', function() {
expect(
function() {
expect('hello world', 'to start with', 'hell yeah');
},
'to throw exception',
"expected 'hello world' to start with 'hell yeah'\n" +
'\n' +
'hello world\n' +
'^^^^'
);
});
});
});

0 comments on commit dcbea8e

Please sign in to comment.