Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should clear basic arrays', function() {
var model = new Model({
beans: []
});
model.fill({ beans: [ 1, 2, 3 ] });
model.clear();
expect(model.beans.length).to.equal(0);
});
it('should serialize on out', function() {
var model = new Model({
id: 12,
name: 'beans'
}),
out;
out = model.out();
expect(Object.keys(out).length).to.equal(2);
expect(out.id).to.equal(12);
expect(out.name).to.equal('beans');
model.extend({
yolo: true,
num: 100
}).fill({
id: 25,
it('should be picky', function() {
var model = new Model({
id: 12,
hashtag: 'yolo'
});
expect(function() {
model.before({
bean() {}
});
}).to.throw(
'Model: called before on a property (bean) that does not exist');
});
it('should clear basic data', function() {
var model = new Model({
id: 12,
name: 'beans',
yolo: true
});
model.fill({
id: 100,
name: 'not beans',
yolo: false,
num: 100
});
model.clear();
expect(model.id).to.equal(12);
expect(model.name).to.equal('beans');
it('should fill sub models defined as properties', function() {
var model = new Model({
id: 47,
sub: SubModel
});
model.fill({
id: 90,
sub: {
id: 34,
name: 'hashtag',
yolo: 'factor'
}
});
expect(model.sub instanceof SubModel).to.be.true;
expect(model.id).to.equal(90);
expect(model.sub.id).to.equal(34);
it('should update on unshifting', function(done) {
var model = new Model({
beans: []
}),
spy = sinon.spy();
model.on_update('beans', spy);
model.beans = [ 1, 2, 3 ];
model.beans.unshift(7, 6, 5);
expect(model.beans.length).to.equal(6);
expect(model.beans[0]).to.equal(7);
expect(model.beans[1]).to.equal(6);
expect(model.beans[2]).to.equal(5);
expect(model.beans[3]).to.equal(1);
expect(model.beans[4]).to.equal(2);
expect(model.beans[5]).to.equal(3);
it('should fill with models', function() {
var model = new Model({
id: 12,
name: 'beans',
yolo: true
});
model.fill(new Model({
name: 'not beans',
yolo: false
}));
expect(model.id).to.equal(12);
expect(model.name).to.equal('not beans');
expect(model.yolo).to.be.false;
});
it('should fill basic data', function() {
var model = new Model({
id: 12,
name: 'beans',
yolo: true
});
model.fill({
name: 'not beans',
yolo: false,
num: 100
});
expect(model.id).to.equal(12);
expect(model.name).to.equal('not beans');
expect(model.yolo).to.be.false;
expect(model.num).to.be.undefined;
});
it('should extend with ease', function() {
var model = new Model({
id: 12,
name: 'beans'
});
expect(model.keys().length).to.equal(2);
model.extend({
yolo: false,
num: 100
});
expect(model.keys().length).to.equal(4);
expect(model.yolo).to.be.false;
expect(model.num).to.equal(100);
});
it('should throw events correctly on fill', function(done) {
var model = new Model({
id: 12,
name: 'beans'
}),
spy1 = sinon.spy(),
spy2 = sinon.spy();
model.on_update('id', spy1);
model.on_update('*', spy2);
model.fill({
id: 56,
name: 'pinto'
});
setTimeout(function() {
try {