Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript library to simulate Internet Explorer JavaScript environment?

This is not a duplicate of the JS library to simulate Internet Explorer? question about simulating Internet Explorer's CSS support; this is about JavaScript functions.

Does a JavaScript library exist which can simulate an environment like Internet Explorer's, whereas JavaScript functions are concerned?

Basically, it would remove/overwrite the functions not supported by older versions of IE (like indexOf, etc.) or at least force any call to them to be ignored somehow.

Effectively, what I'm looking for is something almost like the opposite of Underscore.js and which theoretically could even be used to test (in non-IE browsers) that Underscore.js is doing what it's meant to do.

Or is the amount of effort needed to simulate the environment so small that I can do it quickly myself? If so, how?


The use case I'm imagining:

Using this script to simulate an IE7 environment in Phantom.js's WebKit browser for automated (by Jenkins) JavaScript unit-testing with Jasmine / QUnit / etc (undecided).

like image 593
Adam Lynch Avatar asked Jul 10 '12 09:07

Adam Lynch


2 Answers

I'd advise against that, because you'd be testing how well you support this simulation then, not IE7 itself. IE7 engine is mostly compliant with standards, save for a few quirks (like bad reaction at dangling commas) and of course, missing environment from most recent standards. Most of those quirks are either in line with other browsers or cannot be easily emulated without writing complete JS engine in JS. You may want to consult a list on ES wiki for more details (and note "FF/Opera/Safari: same" sections, where you will likely want not to account for IE's discrepancies with ES).

Your best bet would be to either use a real IE7, that, BTW, have very good automation interface for pretty much any testing, or, at very least, more recent IE version with compatibility mode turned on.

like image 92
Oleg V. Volkov Avatar answered Oct 21 '22 08:10

Oleg V. Volkov


You may be after something like this: http://triflejs.org/ (currently in beta)

Its an IE port of phantomjs for running Headless UI tests.

Like phantom, it uses V8 for running javascript API executable scripts, and instead of webkit it uses the.NET WebBrowser class for instantiating a bare-bones IE engine.

IE provides an emulation environment for running earlier versions so this will run as IE7, IE8 and IE9 if you have IE9 installed.

enter image description here

like image 21
Steven de Salas Avatar answered Oct 21 '22 06:10

Steven de Salas