-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCommandSpec.js
More file actions
53 lines (41 loc) · 1.54 KB
/
CommandSpec.js
File metadata and controls
53 lines (41 loc) · 1.54 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
describe("Backbone.Command",function() {
it("is present", function() {
expect(Backbone.Command).not.toBeUndefined();
});
it("can be instantiated", function() {
var commandInstance = new Backbone.Command();
expect(commandInstance).toBeDefined();
});
it("has a execute method", function() {
var commandInstance = new Backbone.Command();
expect(typeof commandInstance.execute).toEqual("function")
});
it("can be extended", function() {
var ExtendedCommand = Backbone.Command.extend({
execute: function() {
//My execution logic
return "my overridden execute method";
}
});
var commandInstance = new Backbone.Command();
var extendedCommandInstance = new ExtendedCommand();
expect(extendedCommandInstance).toBeDefined();
expect(extendedCommandInstance.execute()).toEqual("my overridden execute method");
expect(commandInstance.execute()).not.toEqual("my overridden execute method");
});
it("can be injected", function() {
var ExtendedCommand = Backbone.Command.extend({
model: 'inject'
});
var model = new Backbone.Model();
var injectorInstance = new injector.Injector();
injectorInstance.map('model').toValue(model);
var extendedCommandInstance = new ExtendedCommand({injector:injectorInstance});
expect(extendedCommandInstance.model).toEqual(model);
});
it("automatically injects the injector", function() {
var injectorInstance = new injector.Injector();
var commandInstance = new Backbone.Command({injector:injectorInstance});
expect(commandInstance.injector).toEqual(injectorInstance);
});
});