writing the test cases

8 views
Skip to first unread message

china

unread,
Oct 2, 2019, 2:21:47 PM10/2/19
to Angular and AngularJS discussion
Hi Experts,

I am new in writing Angular test cases using Karma .I am using Angular js version 1.5.8.......... I got stuck in writing the test cases for the below code ......Help me with this...

function setColor() {
var layoutValue = 'red';
var finalLayout = 'single_asset_promo_module';
if(layoutValue) {
someService.get('id')
.then(function(childNode) {
var newData = {
nid: 'nid',
type: [{value: 'target_id'}],
color: childNode.field_promo_text_color
};
execUpdate(newData);
});
}
else if (layoutValue === 'someother_color' ) {
if('value') {
var newData = {
nid: [{value: 'target_id'}],
type: [{target_id: 'promo'}],
field_promo_text_color: 'field_band_text_color',
};
execUpdate(newData);
}
}

return finalLayout;
}

Sander Elias

unread,
Oct 3, 2019, 1:55:55 AM10/3/19
to Angular and AngularJS discussion
Hi China,

Are you aware that the else case will never be fired?
For the test, it will be hard to test, as there are no inputs to this function, but you can create a mock or spy for someService, and check if it gets called.
Then use the mock/spy to pass in a known value, and you can test that in a mock/spy of execUpdate

Regards
Sander
Reply all
Reply to author
Forward
0 new messages