Permalink
Browse files

Add tests for pull #48

  • Loading branch information...
1 parent cd4c2b1 commit 6558c01ca4650d5e78fccdf5cc8a133a5c6ad7c6 Casey O'Hara committed Oct 8, 2012
Showing with 50 additions and 3 deletions.
  1. +21 −3 src/retina.js
  2. +29 −0 test/retina_test.js
View
@@ -42,6 +42,9 @@
}
+
+
+
function RetinaImage(el) {
this.el = el;
this.path = new RetinaImagePath(this.el.getAttribute('src'));
@@ -71,9 +74,18 @@
- if (root.devicePixelRatio > 1) {
- var existing_onload = window.onload || new Function;
- window.onload = function() {
+
+
+ function Retina() {}
+
+ root.Retina = Retina;
+
+ Retina.init = function(context){
+ if (context == null) context = root;
+
+ var existing_onload = context.onload || new Function;
+
+ context.onload = function() {
var images = document.getElementsByTagName("img"), retinaImages = [], i, image;
for (i = 0; i < images.length; i++) {
image = images[i];
@@ -83,4 +95,10 @@
}
}
+
+
+ if (root.devicePixelRatio > 1) {
+ Retina.init(root);
+ }
+
})();
View
@@ -0,0 +1,29 @@
+// Create a document object because we don't have one
+// in our Node test environment
+global.document = {
+ // stub out the getElementsByTagName method
+ getElementsByTagName : function(){
+ return [];
+ }
+}
+
+
+var Retina = require('../').Retina;
+
+describe('Retina', function() {
+
+ describe('init', function(){
+ it('stashes the existing onload and executes it later', function(){
+ var existingOnloadExecutions = 0;
+ var window = {
+ onload : function() {
+ existingOnloadExecutions++;
+ }
+ };
+ Retina.init(window);
+ window.onload();
+ existingOnloadExecutions.should.equal(1);
+ });
+ });
+
+});

0 comments on commit 6558c01

Please sign in to comment.