-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy path8-unit-tests.js
46 lines (32 loc) · 1.63 KB
/
8-unit-tests.js
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
/*global QUnit, test, equal, ok*/
(function(undefined) {
"use strict";
browserify.done.eight = true;
QUnit.module("Browserify - client code");
var isIE8 = window.attachEvent && !window.addEventListener;
if (!isIE8) {
QUnit.test("No jQuery global: require('jsviews')", function(assert) {
// ............................... Hide QUnit global jQuery and any previous global jsrender.................................
var jQuery = global.jQuery, jsr = global.jsrender;
global.jQuery = global.jsrender = undefined;
// =============================== Arrange ===============================
var data = {name: "Jo"};
// ................................ Act ..................................
var $jq = require('jquery');
var $jsr = require('../../')($jq); // Provide jQuery, so $jsr === $jq is local jQuery namespace
// Use require to get server template, thanks to Browserify bundle that used jsrender/tmplify transform
var tmpl = require('../templates/name-template.html')($jsr); // Provide $jsr
var result = tmpl(data);
$jsr.observe(data, "name", function(ev, eventArgs) {
result += " " + eventArgs.value;
})
$jsr.observable(data).setProperty("name", "new name"); // result === "new name"
result += " " + ($jsr !== jQuery && $jsr === $jq);
// ............................... Assert .................................
assert.equal(result, "Name: Jo (name-template.html) new name true", "result: No jQuery global: require('jsviews')");
// ............................... Reset .................................
global.jQuery = jQuery; // Replace QUnit global jQuery
global.jsrender = jsr; // Replace any previous global jsrender
});
}
})();