Beispiel #1
0
test('Node Style Callbacks', function(t) {

  t.plan(2);

  var idTimeout = setTimeout( function() {
    t.fail("It doesn't look like you called the callback for both images");
    t.end();
  }, 3000);

  usersExport(URL_PASS, URL_FAIL, callBack);

  function callBack(error, image) {
    
    if(error) {
      if(error.message.indexOf(URL_FAIL) > -1 ) {
        t.pass('imageURL1 returned an Error');
      } else {
        t.fail('imageURL1 should not have failed');
      }
    } else if(image.src.indexOf(URL_PASS)) {
      t.pass('imageURL1 loaded properly');
      document.body.appendChild(image);
    } else if(image.src.indexOf(URL_FAIL)) {
      t.fail('imageURL2 should have failed'); 
    } else if(image === undefined) {
      t.fail('One of the callbacks did not return an error or a url');
    }
  }
});
Beispiel #2
0
test('Added and removed events', function(t) {

	var didRollOver = false;
	var didRollOut = false;
	var didClick = false;

	var onTestRollOver = function() {
		didRollOver = true;	
	};

	var onTestRollOut = function() {
		didRollOut = true;
	};

	var onTestClick = function() {
		didClick = true;
	};

	button.addEventListener('mouseout', onTestRollOut);

	usersExport(button, onTestRollOver, onTestRollOut, onTestClick);

	button.addEventListener('click', function() {

		button.dispatchEvent(new MouseEvent('mouseover'));
		button.dispatchEvent(new MouseEvent('mouseout'));

		if(didRollOver) {
			

			if(button.onmouseover == onTestRollOver) {
				t.fail('event listener was added through onmouseover instead of addEventListener');
			} else {
				t.pass('added onTestRollOver to "mouseover"');
			}
		} else {
			t.fail('you should add onTestRollOver to "mouseover"');	
		}

		if(didClick) {
			if(button.onclick == onTestRollOver) {
				t.fail('event listener was added through onclick instead of addEventListener');
			} else {
				t.pass('added onTestClick to "click"');		
			}
		} else {
			t.fail('you should add onTestClick to "click"');	
		}

		if(didRollOut) {
			t.fail('you should remove onTestRollOut to "mouseout"');
		} else {
			t.pass('removed onTestRollOut from "mouseout"');
		}

		t.end();
	});
});