Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function substringAfterLast( str, search, fromIndex ) {
}
if ( arguments.length > 2 ) {
if ( !isInteger( fromIndex ) ) {
throw new TypeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%s`.', fromIndex ) );
throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', fromIndex ) );
}
idx = str.lastIndexOf( search, fromIndex );
} else {
Expand Down
33 changes: 33 additions & 0 deletions lib/node_modules/@stdlib/string/substring-after-last/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,35 @@ tape( 'the function throws an error if not provided a string as its second argum
}
});

tape( 'the function throws an error if not provided an integer as its third argument', function test( t ) {
var values;
var i;

values = [
1.5,
-1.5,
NaN,
'5',
true,
null,
void 0,
[],
{},
function noop() {}
];

for ( i = 0; i < values.length; i++ ) {
t.throws( badValue( values[i] ), /Third argument must be an integer/, 'throws an error when provided '+values[i] );
}
t.end();

function badValue( value ) {
return function badValue() {
substringAfterLast( 'beep', 'b', value );
};
}
});

tape( 'the function returns the substring after the last occurrence of a provided search string', function test( t ) {
var expected;
var actual;
Expand Down Expand Up @@ -155,6 +184,10 @@ tape( 'the function returns the substring after the last occurrence of a provide
expected = '';
t.strictEqual( actual, expected, 'returns expected value' );

actual = substringAfterLast( 'beep', 'b', -1 );
expected = 'eep';
t.strictEqual( actual, expected, 'returns expected value' );

t.end();
});

Expand Down
Loading