gpt4 book ai didi

javascript - 数据类型 Jasmine

转载 作者:行者123 更新时间:2023-11-29 16:50:16 25 4
gpt4 key购买 nike

我是使用 jasmine 进行 Angular Testing 的初学者,我需要测试数据类型(例如 String、int 等)

这是我的 Controller ,我的数据被实例化为空,稍后它将是一个字符串:

_this.instance = {
template_fields: {
guid: null
}
}

// It becomes string
<input type="radio" ng-model="prCreateCtrl.instance.template_fields.guid" value="{{template.guid}}" required>

这是我的测试:

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();
});

我不明白什么时候应该给出一个字符串以及如何测试它。使用 instanceof String 的方式是否正确?

最佳答案

您可以简单地使用 jasmine.any() 函数。

在你的例子中,在 it() block 中:

expect(ctrl.instance.template_fields.guid).toEqual(jasmine.any(String));

关于javascript - 数据类型 Jasmine ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36737612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com