Last active
May 10, 2020 23:26
-
-
Save johncaruso/d8de303a351c7dd01963e1599ebf9c79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * ServiceNow JavaScript Bugs | |
| * | |
| * Executes a suite of tests to verify proper JavaScript implementation. | |
| * Test failures will output "FAIL: expected <actual> to be <expected>" after test description. | |
| * Or produce compiler exception, e.g.: 'Allows keywords as property names' test. | |
| * Outputs using console.log() if console object is found (i.e., browser or node.js), | |
| * otherwise uses gs.info(). | |
| */ | |
| /* globals gs */ | |
| (function () { | |
| function assertEquals (actual, expected) { | |
| return actual === expected ? 'pass' : 'FAIL: expected "' + actual + '" to be "' + expected + '"'; | |
| } | |
| var tests = { | |
| /** global scope: Javascript compiler exception: invalid property id (null.null.script; line 19) in: */ | |
| 'Allows keywords as property names': function () { | |
| var obj = { name: 'John', new: 'new', long: 'long', default: 'default' }; | |
| return assertEquals(obj.default, 'default'); | |
| }, | |
| /** global scope FAIL **/ | |
| 'Empty Array evaluates to true': function () { | |
| return assertEquals(!![], true); | |
| }, | |
| /** global scope FAIL **/ | |
| 'Calling undefined method should throw catchable error': function () { | |
| var result = 'uncaught', | |
| clazz = {}; | |
| try { | |
| clazz['method'](); | |
| } catch (e) { | |
| result = 'caught'; | |
| } | |
| return assertEquals(result, 'caught'); | |
| } | |
| }; | |
| var log = (function () { | |
| if (typeof console === 'undefined') | |
| return function (s) { | |
| gs.info(s); | |
| }; | |
| return function (s) { | |
| console.log(s); | |
| }; | |
| })(); | |
| var result = ''; | |
| for (var test in tests) { | |
| try { | |
| result = tests[test](); | |
| } catch (e) { | |
| result = 'FAIL: unhandled exception: ' + e; | |
| } | |
| log(test); | |
| if (result !== 'pass') log('\t' + result); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment