You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I wanted to make sure the validations were working in the defined resources. What do you think a good test would be for that?
it('validates data before creation',function(){varinvalidEvnt=angular.extend(testEvnt,{startDate: false// must be a Date object and must be less than endDate.});// Have to return something here;DS.expectCreate('evnt',invalidEvnt).respond(newError('invalid'));Evnt.create(invalidEvnt).then(function(result){fail('should have rejected');},function(err){//This will just return the error I created, thus the test is a little useless.});});
The text was updated successfully, but these errors were encountered:
If the test isn't useful without the functionality of the real data store, then the test needs to use the real data store.
The mock data store is useful when you want to test your own logic (the validate function), ignoring what the real data store would do (save to localStorage, make an http request, etc.). You didn't post your resource definition, but I'm guessing it's something like:
functionvalidateEvnt(resourceName,attrs,cb){if(!angular.isDate(attrs.startDate)||attrs.startDate<attrs.endDate){cb('startDate must be a date and less than endDate!');}else{cb(null,attrs);}}varEvnt=DS.defineResource({name: 'evnt',validate: validateEvnt});
So to test that your validate function does what it should:
it('should validate',function(){validateEvnt({startDate: false},function(err,attrs){assert.equal(err,'startDate must be a date and less than endDate!');});});
If you want to test that angular-data calls your validate function like it should, then you're welcome to contribute to angular-data's tests.
If you really want to test your validation function's integration with angular-data, then that test will need to use the real data store. All of the methods in angular-data-mocks are stubs.
So I wanted to make sure the validations were working in the defined resources. What do you think a good test would be for that?
The text was updated successfully, but these errors were encountered: