-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
81 lines (66 loc) · 1.94 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!doctype html>
<html>
<head>
<title>define.async test</title>
<script src="require.js"></script>
<script src="async.js"></script>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script>
function log(str) {
$('#log').append($('<div>').text(str));
}
function test(id, actual, expected) {
if (actual !== expected) {
log(id + '. Nope. Actual: ' + actual + ' Expected: ' + expected);
} else {
log(id + '. Yep.');
}
}
define('dep', function () {
return 'yeah';
});
define.async('test', ['dep'], function (dep) {
// no data in the beginning
var data = {};
// common module definition but we don't return this
var module = {
a: function () {
return dep;
},
b: function () {
return data;
}
};
// load data
return $.ajax({ url: 'test.json' }).then(function (response) {
data = response;
$('h1').text('resolved');
return module;
});
});
$(function () {
var text, module;
test('define is a function', typeof window.define, 'function');
test('define.async() is a function', typeof window.define.async, 'function');
text = $('h1').text();
test('module is unresolved', text, 'unresolved');
require(['test'], function (module) {
text = $('h1').text();
test('module is resolved', text, 'resolved');
test('module is defined', module !== undefined, true);
test('module has proper dependency a()', typeof module.a, 'function');
test('dependency returns proper value', module.a(), 'yeah');
test('module has proper method b()', typeof module.b, 'function');
var data = module.b();
test('method b() returns data', data !== undefined, true);
test('method b() returns correct data', data.hello, 'world');
$('h1').text('Done');
});
});
</script>
</head>
<body>
<h1>unresolved</h1>
<div id="log"></div>
</body>
</html>