Promises are the new way™ to express "Do this, and once you're done, do that". In contrast to callbacks...
...s legendary Functional library, here’s a lightweight tool to help keep track of JavaScript invocations. It works in Chrome, Safari, Firebug and IE8...
Attached (see below) is some code to allow using unobtrusive JavaScript on pages fetched with an AJAX call. After you included it, you now do not use the usual
...unobtrusive() to register new element activation callbacks $.unobtrusive = function(callback) { $(document).on('activate-unobtrusive-javascript', function(event, root) { $(root).each(callback); }); } // Define a function for all jQuery collections to manually...
...Using jasmine.clock().mockDate() you can mock new Date() (which returns the current time in Javascript) While you can use SinonJS Fake timers, using the built-in Jasmine clock will save...
...t been written down in this deck before, here it goes: When working with JavaScript Event objects, the DOM element that triggered the event is attached to them. [1]
...logs out the user). Rails probably does this because CSRF protection sort of requires Javascript. You want to enable CSRF protection in Cucumber scenarios that can speak Javascript. To do...
...and mocks in Cucumber rspec_candy Cucumber: Detect if the current Capybara driver supports Javascript
JavaScript's NaN ("Not a Number") is hard to compare against. It never equals anything, not even itself: NaN === NaN; // false Number.NaN === NaN; // false There is the isNaN method, but...
...implements the technique in this card with tests and all caveats fixed. Related topic: JavaScript: Working with Query Parameters Javascript: Read params from url...
...non-breaking spaces or hyphens of various lengths. For this, use the ways below. Javascript, Coffeescript Use the \u escape sequence: note = '\u266A' You can use Unicode escape sequences in...
Getting a regular expression from a string in JavaScript is quite simple: new RegExp('Hello Universe'); # => /Hello Universe/ You can also use special characters: new RegExp('^(\\d+) users') # => /^(\d+) users...
Single step and slow motion for Cucumber scenarios can come in handy, especially in @javascript scenarios. # features/support/examiners.rb AfterStep('@slow_motion') do sleep 2 end AfterStep('@single_step') do print "Single...
...Note: You can also prevent the selenium webbrowser window from closing after a failed @javascript step. Fixing out-of-sync Cucumber output The problem with the @slow_motion step above...
...Although there is no equivalent to this idiom in naked Javascript, there is a way to collect object properties (but not method results) if you are using common Javascript libraries...
If some of your JavaScripts fail on Internet Explorer, but only in staging or production environments, chances are that JavaScript compression is the culprit. By default, Rails 3.2 compresses JavaScript...
...with UglifyJS. I have seen a few cases where this actually breaks functioning JavaScript on IE (one example is the CKEditor). I fixed this by switching to Yahoo's YUI...
Controller responses often include Javascript code that contains values from Ruby variables. E.g. you want to call a Javascript function foo(...) with the argument stored in the Ruby variable @foo...
...by sprockets) has a nice feature where templates ending in .jst are compiled into Javascript template functions. These templates can be rendered by calling JST['path/to/template'](template: 'variables'): Hello, <%= name...
...templates/hello $("#hello").html(JST["templates/hello"]({ name: "Sam" })); Whatever is in the <%...
...%> is evaluated in Javascript. You can also use CoffeeScript here: Sprockets supports two JavaScript template languages: EJS, for embedded...
If you are writing any amount of Javascript, you are probably using closures to hide local state, e.g. to have private methods. In tests you may find it necessary to...
JavaScript structures that include circular references can't be serialized with a"plain" JSON.stringify. Example: a = { name: 'Groucho' }; b = { name: 'Harpo', sibling: a }; a.sibling = b; Doing a JSON.stringify(a) will...
Use this if you want to show or hide part of a form if certain options are selected or boxes...
To simulate Rails' to_sentence in your JavaScript application, you can use these few lines of CoffeeScript code: joinSentence = (array) -> if array.length > 1 array[0..-2].join(', ') + ', and ' + array...
...cats', 'dogs', 'pandas']) # => 'cats, dogs, and pandas' ^ > joinSentence(['llamas']) # => 'llamas' Here is some plain JavaScript, should you prefer that: function joinSentence(array) { if (array.length > 1) { return array.slice(0, -1).join...
Great presentation about writing Javascript like you write everything else: Well-structured and tested. JavaScript is no longer a toy language. Many of our applications can’t function without it...
...If we are going to use JavaScript to do real things, we need to treat it like a real language, adopting the same practices we use with real languages.
Less.js is a JavaScript implementation of LESS that’s run by your web browser. As any JavaScript, you include a link to the script in your HTML, and…that’s...
You can easily have a JavaScript hash/object that returns a default value for unset keys/properties -- as long as you need to support only recent browsers. The key are JavaScript proxies...
ExecJS lets you run JavaScript code from Ruby. It automatically picks the best runtime available to evaluate your JavaScript program, then returns the result to you as a Ruby object...
Selenium has been the siren song that continually calls out to us. Unfortunately, in practice we’ve been unable to...