I created an instance function on a Model as per this spec:
describe('Instance methods', function() {
var task;
beforeEach(function() {
return Task.create({
name: 'task',
}).then(function(_task) {
task = _task;
});
});
describe('addChild', function() {
it('should return a promise for the new child', function() {
return task.addChild({ name: 'task2' }).then(function(child) {
expect(child.name).to.equal('task2');
expect(child.parentId).to.equal(task.id);
});
});
});
..... more not applicable
});
This is it, but I am not getting zilch back...
Task.prototype.addChild = function(task) {
return Task.create(task.name).then(function(task) {
console.log('task', task);
return task;
});
};
As mentioned in the spec:
should return a promise for the new child
And as per the console:
Task Instance methods addChild should return a promise for the new child:
And this is the error I am getting back:
SequelizeValidationError: Validation Error
So what I am doing wrong to not add this task in the data base?
Am I not using the create method correctly?
Thanks in advance!
UPDATE
I tried this:
Task.prototype.addChild = function(task) { var task = Task.build({
name: task['name'] }); return task.save(); };
But I am getting back,
AssertionError: expected null to equal 1