backbone-seen.spec.js 1.84 KB
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);
        });
    });
});