torque/test/request.js

33 lines
884 B
JavaScript
Raw Normal View History

2014-12-09 22:46:03 +08:00
var torque = require('../lib/torque/core');
2013-11-09 17:12:37 +08:00
2014-12-09 22:46:03 +08:00
QUnit.module('request');
asyncTest("json", 6, function(assert) {
2013-11-09 17:12:37 +08:00
var called = null;
torque.net.jsonp('http://test.com?callback=?', function(test) {
called = arguments;
});
setTimeout(function() {
var scripts = document.getElementsByTagName('script');
var found = null;
for (var i = 0 ; !found && i < scripts.length; ++i) {
var s = scripts[i];
if (s.getAttribute('src').indexOf('test.com') !== -1) {
found = s;
}
}
var src = found.getAttribute('src');
var fnName = src.match(/torque_.*/);
window[fnName]('test1', 2, null);
equal(src.indexOf('http://test.com?callback=torque_'), 0);
equal(called[0], 'test1');
equal(called[1], 2);
equal(called[2], null);
equal(found.parent, null);
equal(window[fnName], undefined);
QUnit.start();
}, 5);
});