开关条件有布尔值?(switch condition has boolean value?)
这段代码似乎完全合乎逻辑 为什么我得到“开关条件具有布尔值”错误? 我用它来切换
UIButton
上的文字。 它的工作原理,但我仍然有错误。bool buttonSunStatus = TRUE; - (void) useButtonSun:(id)sender { buttonSun = [UIButton buttonWithType: UIButtonTypeCustom]; switch (buttonSunStatus) { case TRUE: [sender setTitle:@"No Sun" forState:UIControlStateNormal]; buttonSunStatus = FALSE; break; case FALSE: [sender setTitle:@"Sun" forState:UIControlStateNormal]; buttonSunStatus = TRUE; break; } }
This code seems perfectly logical. Why am I getting the "Switch condition has boolean value" error? I'm using it to switch the literals on a
UIButton
. It works but I still have the error.bool buttonSunStatus = TRUE; - (void) useButtonSun:(id)sender { buttonSun = [UIButton buttonWithType: UIButtonTypeCustom]; switch (buttonSunStatus) { case TRUE: [sender setTitle:@"No Sun" forState:UIControlStateNormal]; buttonSunStatus = FALSE; break; case FALSE: [sender setTitle:@"Sun" forState:UIControlStateNormal]; buttonSunStatus = TRUE; break; } }
原文:https://stackoverflow.com/questions/26411482
最满意答案
我最终找到了使用karma-systemjs的解决方案。
在systemjs / files部分包含所有测试文件:
systemjs: { files: [ // TEST FILES ], configFile: 'system.config.js', config: { paths: { 'angular-mocks': 'node_modules/angular-mocks/angular-mocks.js' } } }
而在测试而不是使用:
System.import('boot');
使用:
'use strict'; import 'angular-mocks'; import 'angular/boot.js'; describe('Controller: B', function() { beforeEach(module('app')); var $scope; beforeEach(inject(function(_$rootScope_, $controller) { scope = _$rootScope_.$new(); $controller('B', {$scope: $scope); })); it('...', function() { }); });
希望这将有助于将来的其他人。
The solution I ended up finding involved using karma-systemjs.
Include all your tests files on the systemjs/files section:
systemjs: { files: [ // TEST FILES ], configFile: 'system.config.js', config: { paths: { 'angular-mocks': 'node_modules/angular-mocks/angular-mocks.js' } } }
And on the tests instead of using:
System.import('boot');
Use:
'use strict'; import 'angular-mocks'; import 'angular/boot.js'; describe('Controller: B', function() { beforeEach(module('app')); var $scope; beforeEach(inject(function(_$rootScope_, $controller) { scope = _$rootScope_.$new(); $controller('B', {$scope: $scope); })); it('...', function() { }); });
Hopefully this will help someone else in the future.
相关问答
更多-
我在Browserify和JSX上使用ES6。 编译我使用Babel。 以下配置适用于我。 karma.conf.js ... frameworks: ['browserify', 'jasmine'], files: [ 'Component.js', // replace with your component '__tests__/Component-test.js' ], preprocessors: { 'Component.js': 'brow ...
-
ES5与ES6承诺(ES5 vs ES6 Promises)[2023-05-16]
ES5没有承诺。 像jQuery或Angular这样的库有自己的定制和非标准的promise实现。 与ES5一起使用的受欢迎的Promise实现是Bluebird(它与ES6标准兼容)和Q(它最初并不与ES6标准兼容 - 尽管似乎正在朝着这个方向发展)和RSVP。 也不是真正的polyfills,因为如果有本地承诺存在,它们不会妨碍它们,因为它们增加了额外的功能。 ES6承诺有一些纯粹的polyfills。 以下是RSVP的一个子集: https : //github.com/stefanpenner/es ... -
您在测试中包含已转换的文件。 例如,在错误中查看此行: WARNING in ./~/routes/dist/routes.js Critical dependencies: 1:406-413 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results. @ ./~/r ...
-
我实际上建议采用略有不同的测试方法。 如果目标是测试SideNavController中的逻辑,我会考虑将该类移动到它自己的文件中。 这样你就可以在指令和测试中导入它。 以这种方式构建它可以让您更容易地访问它,因为您可以完全独立于指令本身进行测试。 通过编译标记和创建整个指令来测试它基本上将其转换为集成测试,并且管理起来有点复杂。 一般来说,我发现这可以提供更多可维护和有用的测试 - 特别是如果目标是测试控制器。 它与我的例子类似: http : //www.syntaxsuccess.com/viewar ...
-
角度constant服务只是一种在配置阶段可用的服务,是存储模块常量的建议方式(因此名称)。 它不是一个真正的常量,可以随时用$provide.constant覆盖。 链式angular.module(...)导出Module对象 ,在非Angular上下文中没有意义。 为Angular模块和ES6模块保留单独的导出。 导出Angular模块name属性是一种常规方法,该属性可以在语义上导入并在其他模块中使用。 export const foo = ...; export default angular. ...
-
我最终找到了使用karma-systemjs的解决方案。 在systemjs / files部分包含所有测试文件: systemjs: { files: [ // TEST FILES ], configFile: 'system.config.js', config: { paths: { 'angular-mocks': 'node_modules/angular-mocks/angular-mo ...
-
使用TS可能会更容易升级到Angular(2+)。 除此之外,特别是使用ES6 / TS而不是VanillaJS的Vanilla JS没有特别的好处。 与Vanilla JS相比,使用ES6 / TS有一般的好处(和权衡)。 将不会遇到AngularJS特定的问题,而使用TS / ES将使组织代码,代码可理解性等的生活更容易..如此处和此处所述。 Using TS will probably make it easier to upgrade to Angular (2+). Other than that ...
-
角度5与es5(Angular 5 with es5)[2023-05-05]
您需要在组件 类 函数上使用静态属性annotations和parameters ,如下所示: function Service() {} function AppComponent(service) { console.log(service); } AppComponent.prototype.ngOnInit = function() { console.log('test ngOnInit'); }; AppComponent.annotations = [ new Compone ... -
super($rootScope, $state, $log); 调用父构造函数。 你有 this.activate(); 由于this是ConversationDetailController一个实例,因此调用其activate方法,而不是ConversationListController 。 你有 let id = this.$stateParams.id; 但$stateParams尚未设置,因为: super($rootScope, $state, $log); <- You are her ...
-
$scope.Contact.title = $scope.doctitles[$scope.doctitles.findIndex(function(x) { return x.id == $localStorage.data.contacts[$localStorage.data.itemID].title.id; })]; 您只需用函数替换lambda即可。 编辑:由于findIndex也是ES6,你可以使用这个polyfill: if (!Array.prototype.findIndex ...