Skip to content

Commit

Permalink
Fix teaspoon tests (headless)
Browse files Browse the repository at this point in the history
Seems that the polyfilled teaspoon Function.prototype.bind support for PhantomJS is not compatible with Ember 1.9. Used a shim from React instead.

See also facebook/react#945
  • Loading branch information
watsonbox committed Dec 29, 2014
1 parent 1ecf720 commit 21768b6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion spec/javascripts/spec_helper.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#
# PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion.
# Use this polyfill to avoid the confusion.
#= require support/bind-poly
# Had to use the following shim from react to get working with Ember 1.9:
# https://raw.githubusercontent.com/facebook/react/master/src/test/phantomjs-shims.js
#= require support/bind-poly-phantomjs
#
# Deferring execution
# If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call
Expand Down
37 changes: 37 additions & 0 deletions spec/javascripts/support/bind-poly-phantomjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// https://raw.githubusercontent.com/facebook/react/master/src/test/phantomjs-shims.js

(function() {

var Ap = Array.prototype;
var slice = Ap.slice;
var Fp = Function.prototype;

if (!Fp.bind) {
// PhantomJS doesn't support Function.prototype.bind natively, so
// polyfill it whenever this module is required.
Fp.bind = function(context) {
var func = this;
var args = slice.call(arguments, 1);

function bound() {
var invokedAsConstructor = func.prototype && (this instanceof func);
return func.apply(
// Ignore the context parameter when invoking the bound function
// as a constructor. Note that this includes not only constructor
// invocations using the new keyword but also calls to base class
// constructors such as BaseClass.call(this, ...) or super(...).
!invokedAsConstructor && context || this,
args.concat(slice.call(arguments))
);
}

// The bound function must share the .prototype of the unbound
// function so that any object created by one constructor will count
// as an instance of both constructors.
bound.prototype = func.prototype;

return bound;
};
}

})();

0 comments on commit 21768b6

Please sign in to comment.