最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Data Type Jasmine - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 7

You 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 :)

发布评论

评论列表(0)

  1. 暂无评论