JS *_*rah 3 coldfusion bdd coldfusion-2016
更新:提交了此问题的错误报告,Bug#4150051
您可以调用?:作为elvis运算符/三元运算符/ null coelcing.在ACF中关于此运算符的适当文档的实现和运气非常差.在TestBox中使用它时遇到了一些问题(试过v2.3.0 + 00044和2.2.0 + 00021)BDD.在这里,我创建了非常简单的测试包(aTest.cfc)来演示这个问题.
component extends="testbox.system.BaseSpec"{
function run(){
describe( "checking the ACF issues in ternary operaors", function(){
it( "Just dump, it will pass. But see the dump above", function(){
itemTypeConfig = {};
writeDump( itemTypeConfig.someConfig ?: "I am null" );
itemTypeConfig = {"someConfig":"abcd"};
writeDump( itemTypeConfig.someConfig ?: "I am null" );
} );
it( "Check with elvis operator inside expect", function(){
itemTypeConfig = {};
expect( itemTypeConfig.someConfig ?: "I am null" ).toBe(1);
itemTypeConfig = {"someConfig":"abcd"};
expect( itemTypeConfig.someConfig ?: "I am null" ).toBe(1);
} );
it( "Check with expect with some temp variable", function(){
itemTypeConfig = {};
var actualResult = itemTypeConfig.someConfig ?: "I am null";
expect( actualResult ).toBe(1);
itemTypeConfig = {"someConfig":"abcd"};
var actualResult = itemTypeConfig.someConfig ?: "I am null";
expect( actualResult ).toBe("abcd");
} );
it( "Check with expect with struct key exists", function(){
itemTypeConfig = {};
if ( structkeyexists(itemTypeConfig, "someConfig") )
var actualResult = itemTypeConfig.someConfig;
else
var actualResult = 1;
expect( actualResult ).toBe(1);
itemTypeConfig = {"someConfig":"abcd"};
if ( structkeyexists(itemTypeConfig, "someConfig") )
var actualResult = itemTypeConfig.someConfig;
else
var actualResult = 1;
expect( actualResult ).toBe("abcd");
} );
} );
}
}
Run Code Online (Sandbox Code Playgroud)
在Lucee运行此测试用例时,没有问题.但是在Adobe ColdFusion中,我遇到了错误.参考附上测试结果的屏幕截图.
你可以看到转储在第一个规范中未定义.
在第二个规范中,如果你将elvis操作符放在expect中,那么expect( itemTypeConfig.someConfig ?: "I am null" ).toBe(1);它将给出实际的undefined
在第三个规格,我想使用临时变量作为变通方法来解决实际的不确定问题规范2
itemTypeConfig = {};
var actualResult = itemTypeConfig.someConfig ?: "I am null";
expect( actualResult ).toBe(1);
,但它给actualResult未定义
在第四个规范中,我正在使用struckkeyexists在BDD测试套件中使用这个三元运算符并且它工作正常.
我试图在独立的cfm文件中创建类似的行为,但我无法重现它.我不确定,它是在testbox中是问题还是可能是ACF处理闭包内的elvis操作符.我不确定描述此问题的确切术语
这是Adobe ColdFusion Release 2016中的解析错误.(它适用于ColdFusion 11).我将您的示例简化为此代码,以演示此问题.只有当你将闭包调用嵌套至少2深时才会发生这种情况.
clos = function( func ) { func(); };
clos( function(){
clos( function(){
writeDump( foo ?: "I am null" );
} );
} );
Run Code Online (Sandbox Code Playgroud)
您报告的输出是" 未定义的 ",但预期" 我为空 ".
请转到Adobe Bug库并输入票证.在修复之前,您将无法在BDD测试中使用elvis运算符.
我建议简化你的问题来使用这个,更小的repro案例.