parseOnLoadDeclarativeRequire.html
2.39 KB
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
<!DOCTYPE html>
<html>
<head>
<title>parseOnLoad:true, async:false unit test</title>
<style type="text/css">
@import "../../resources/dojo.css";
</style>
<script type="text/javascript" src="../../dojo.js" data-dojo-config="isDebug:true, parseOnLoad: true"></script>
<script type="text/javascript">
require(["doh", "dojo/ready"], function(doh, ready){
ready(function(){
doh.register("parseOnLoad declarative-require", function parseOnLoad(){
doh.is("object", typeof dr1, "dr1 created");
doh.is("bar", dr1.params.foo, "dr1 parameters set on instantiation");
doh.is("object", typeof dr2, "dr2 created");
doh.is("bar", dr2.params.foo, "dr2 parameters set on instantiation");
doh.is("object", typeof dr3, "dr3 created");
doh.is("bar", dr3.params.foo, "dr3 parameters set on instantiation");
doh.is(2, dr4.params.foo, "module loaded and executed");
doh.is(3, dr5.method1(1), "declarative script has access to parser scope");
});
doh.run();
});
});
</script>
</head>
<body>
<h1>parseOnLoad:true, async:false unit test</h1>
<p>This page tests that:</p>
<ol>
<li>parseOnLoad: true parses the page on load</li>
<li>since async:true is NOT set, parseOnLoad:true works (with deprecation message)
even if there's no explicit require() of dojo/parser</li>
<li>the parse happens before the ready() callback happens, including processing of declarative requires</li>
</ol>
<p>See console for test results.</p>
<script type="dojo/require">
AMDWidget: "dojo/tests/resources/AMDWidget",
AMDWidget2: "dojo/tests/resources/AMDWidget2"
</script>
<div data-dojo-id="dr1" data-dojo-type="AMDWidget" data-dojo-props="foo: 'bar'"></div>
<div data-dojo-id="dr2" data-dojo-type="AMDWidget2" data-dojo-props="foo: 'bar'"></div>
<script type="dojo/require">
"acme.AMDWidget3": "dojo/tests/resources/AMDWidget3"
</script>
<div data-dojo-id="dr3" data-dojo-type="acme.AMDWidget3" data-dojo-props="foo: 'bar'"></div>
<script type="dojo/require">
amdmodule: "dojo/tests/resources/amdmodule"
</script>
<div data-dojo-id="dr4" data-dojo-type="AMDWidget" data-dojo-props="foo: amdmodule(1)"></div>
<div data-dojo-id="dr5" data-dojo-type="AMDWidget2">
<script type="dojo/aspect" data-dojo-advice="before" data-dojo-method="method1" data-dojo-args="value">
return [amdmodule(value)];
</script>
</div>
</body>
</html>