Skip to content

Commit

Permalink
add test for multiple custom handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
olslash committed May 26, 2016
1 parent 8c72dd8 commit 2cf3e99
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/__tests__/Linkify-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('Linkify', () => {
});

describe('#addCustomHandlers', () => {
it('should match all custom handlers added through the "handlers" prop', () => {
it('should match a custom handler added through the "handlers" prop', () => {
const linkify = TestUtils.renderIntoDocument(
<Linkify handlers={[{
prefix: '@',
Expand All @@ -145,6 +145,44 @@ describe('Linkify', () => {
expect(output[1].props.href).toEqual(`https://twitter.com/mention`);
expect(output[1].props.children).toEqual(input[1]);
expect(output[2]).toEqual(input[2]);
});

it('should match multiple custom handlers', () => {
const linkify = TestUtils.renderIntoDocument(
<Linkify handlers={[{
prefix: '@',
validate() {
return 7;
},
normalize(match) {
match.url = 'https://twitter.com/' + match.url.replace(/^@/, '');
}
}, {
prefix: '$',
validate() {
return 7;
},
normalize(match) {
match.url = 'https://blingtwitter.com/' + match.url.replace(/^\$/, '');
}
}]}
>
</Linkify>
);

const input = ['this is an ', '@mention', ' and ', '$mention', ' handler'];
const output = linkify.parseString(input.join(''));

expect(output[0]).toEqual(input[0]);
expect(output[1].type).toEqual('a');
expect(output[1].props.href).toEqual(`https://twitter.com/mention`);
expect(output[1].props.children).toEqual(input[1]);

expect(output[2]).toEqual(input[2]);
expect(output[3].type).toEqual('a');
expect(output[3].props.href).toEqual(`https://blingtwitter.com/mention`);
expect(output[3].props.children).toEqual(input[3]);
expect(output[4]).toEqual(input[4]);
})
});

Expand Down

0 comments on commit 2cf3e99

Please sign in to comment.