backbone-seen.spec.js
1.84 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
define(function(require) {
'use strict';
var BackboneSeen = require('backbone-seen');
var Backbone = require('backbone');
describe('BackboneSeen', function() {
it('exists', function() {
expect(BackboneSeen).toBeTruthy();
expect(Backbone.Model.prototype.seen).toBeUndefined();
});
});
describe('BackboneSeen', function() {
var Base, Parent, Child;
beforeEach(function() {
Base = Backbone.Model.extend();
Parent = Base.extend();
Child = Parent.extend();
});
it('mixin', function() {
expect(Base.prototype.seen).toBeUndefined();
expect(Parent.prototype.seen).toBeUndefined();
expect(Child.prototype.seen).toBeUndefined();
var base = new Base({a: '1'});
var parent = new Parent({a: '1'});
var child = new Child({b: 'c'});
expect(base.seen).toBeUndefined();
expect(parent.seen).toBeUndefined();
expect(child.seen).toBeUndefined();
Parent = BackboneSeen.mixin(Parent);
var seen = parent.seen;
expect(base.seen).toBeUndefined();
expect(seen).toEqual(jasmine.any(Function));
expect(child.seen).toBe(parent.seen);
});
it('seen', function() {
Parent = BackboneSeen.mixin(Parent);
var parent = new Parent({a: '1'});
expect(parent.seen()).toEqual([]);
expect(parent.seen('a')).toBe(undefined);
expect(parent.seen('a', true)).toBe(parent);
expect(parent.seen()).toEqual(['a']);
expect(parent.seen('a')).toBe(true);
expect(parent.seen('a', false)).toBe(parent);
expect(parent.seen()).toEqual([]);
expect(parent.seen('a')).toBe(undefined);
});
});
});