-
-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added warning in development mode when rendering link with javascript…
…:url, fixes Github #1594
- Loading branch information
Sampo Kivistö
committed
Jun 17, 2022
1 parent
8d58e6a
commit 7bc3763
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* tslint:disable:no-console */ | ||
import { render } from 'inferno'; | ||
|
||
describe('Links', () => { | ||
let container; | ||
|
||
beforeEach(function () { | ||
container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
}); | ||
|
||
afterEach(function () { | ||
render(null, container); | ||
container.innerHTML = ''; | ||
document.body.removeChild(container); | ||
}); | ||
|
||
describe('javascript href', function () { | ||
it('Should log warning when rendering link starting with javascript::', function () { | ||
spyOn(console, 'error'); | ||
|
||
render(<a href="javascript:foobar">test</a>, container); | ||
|
||
expect(console.error).toHaveBeenCalledTimes(1); | ||
expect(console.error).toHaveBeenCalledWith( | ||
'Rendering links with javascript: URLs is not recommended. Use event handlers instead if you can. Inferno was passed "javascript:foobar".' | ||
); | ||
expect(container.innerHTML).toEqual('<a href="javascript:foobar">test</a>'); | ||
}); | ||
|
||
it('Should allow patching link to null', function () { | ||
spyOn(console, 'error'); | ||
|
||
render(<a href="javascript:foobar">test</a>, container); | ||
|
||
expect(console.error).toHaveBeenCalledTimes(1); | ||
|
||
render(<a>test</a>, container); | ||
|
||
expect(console.error).toHaveBeenCalledTimes(1); | ||
|
||
expect(container.innerHTML).toEqual('<a>test</a>'); | ||
}); | ||
|
||
it('Should not log warning when rendering regular link', function () { | ||
spyOn(console, 'error'); | ||
|
||
render(<a href="https://github.com/infernojs/inferno">test</a>, container); | ||
|
||
expect(console.error).toHaveBeenCalledTimes(0); | ||
expect(container.innerHTML).toEqual('<a href="https://github.com/infernojs/inferno">test</a>'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters