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 bees 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 ?
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 bees 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 ?
Share Improve this question edited Apr 20, 2016 at 8:24 Jagrut 9227 silver badges21 bronze badges asked Apr 20, 2016 at 8:09 user3703539user3703539 4371 gold badge5 silver badges22 bronze badges2 Answers
Reset to default 7You can simply use jasmine.any()
function.
In your case, inside it()
block:
expect(ctrl.instance.template_fields.guid).toEqual(jasmine.any(String));
You can try using toBeInstanceOf
matcher:
Inside it()
block:
expect(ctrl.instance.template_fields.guid).toBeInstanceOf(String);
I think it's simple & makes your test more readable. Have fun :)