I'm a beginner in angular test with jasmine and i need to test data type(e.g. String, int, etc.)
This is my controller, my data is instantiated to null and later it will be a string :
_this.instance = {
template_fields: {
guid: null
}
}
// It becomes string
<input type="radio" ng-model="prCreateCtrl.instance.template_fields.guid" value="{{template.guid}}" required>
This is my test :
beforeEach(inject(function ($state, $controller, $rootScope, $q) {
state = $state.get('app.provision');
ctrl = $controller('ProvisionCreateCtrl', {
instance: {
template_fields: {
guid : {}
}
}
});
}));
it('should resolve data', function () {
expect(ctrl.instance.template_fields.guid instanceof String).toBeTruthy();
});
I don't understand when should I give a String and how can I test it. Is using instanceof String the right way ?
You can simply use jasmine.any()
function.
In your case, inside it()
block:
expect(ctrl.instance.template_fields.guid).toEqual(jasmine.any(String));