-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathtest.require.js
96 lines (80 loc) · 3.04 KB
/
test.require.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
describe("require + define", function () {
it("exist off of cordova", function () {
var cordova = require('cordova');
expect(cordova.require).toBeDefined();
expect(cordova.define).toBeDefined();
});
describe("when defining", function () {
it("can define and remove module", function () {
define("a", jasmine.createSpy());
define.remove("a");
});
it("can remove a module that doesn't exist", function () {
define.remove("can't touch this");
});
it("throws an error the module already exists", function () {
expect(function () {
define("cordova", function () {});
}).toThrow("module cordova already defined");
});
it("doesn't call the factory method when defining", function () {
var factory = jasmine.createSpy();
define("ff", factory);
expect(factory).not.toHaveBeenCalled();
});
});
describe("when requiring", function () {
it("throws an exception when module doesn't exist", function () {
expect(function () {
require("your mom");
}).toThrow("module your mom not found");
});
it("calls the factory method when requiring", function () {
var factory = jasmine.createSpy();
define("dino", factory);
require("dino");
expect(factory).toHaveBeenCalledWith(require,
{}, {
id: "dino",
exports: {}
});
define.remove("dino");
});
it("returns the exports object", function () {
define("a", function (require, exports, module) {
exports.stuff = "asdf";
});
var v = require("a");
expect(v.stuff).toBe("asdf");
define.remove("a");
});
it("can use both the exports and module.exports object", function () {
define("a", function (require, exports, module) {
exports.a = "a";
module.exports.b = "b";
});
var v = require("a");
expect(v.a).toBe("a");
expect(v.b).toBe("b");
define.remove("a");
});
it("returns was is assigned to module.exports", function () {
var Foo = function () { };
define("a", function (require, exports, module) {
module.exports = new Foo();
});
var v = require("a");
expect(v instanceof Foo).toBe(true);
define.remove("a");
});
it("has the id and exports values but not the factory on the module object", function () {
var factory = function (require, exports, module) {
expect(module.id).toBe("a");
expect(module.exports).toBeDefined();
expect(module.factory).not.toBeDefined();
};
define("a", factory);
require("a");
});
});
});