torque/test/request.js

33 lines
947 B
JavaScript
Raw Permalink 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;
2014-12-10 01:11:00 +08:00
torque.net.jsonp('./data/foobar.jsonp.js?callback=?', function(test) {
2013-11-09 17:12:37 +08:00
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];
2014-12-10 01:11:00 +08:00
if (s.getAttribute('src').indexOf('foobar.jsonp.js') !== -1) {
2013-11-09 17:12:37 +08:00
found = s;
}
}
var src = found.getAttribute('src');
var fnName = src.match(/torque_.*/);
window[fnName]('test1', 2, null);
2014-12-10 01:11:00 +08:00
assert.equal(src.indexOf('./data/foobar.jsonp.js?callback=torque_'), 0);
assert.equal(called[0], 'test1');
assert.equal(called[1], 2);
assert.equal(called[2], null);
assert.equal(found.parent, null);
assert.equal(window[fnName], undefined);
2013-11-09 17:12:37 +08:00
QUnit.start();
}, 5);
});