Вот как это работает:
export function getFunctionCallerName (){
// gets the text between whitespace for second part of stacktrace
return (new Error()).stack.match(/at (\S+)/g)[1].slice(3);
}
Затем в ваших тестах:
import { expect } from 'chai';
import { getFunctionCallerName } from '../../../lib/util/functions';
describe('Testing caller name', () => {
it('should return the name of the function', () => {
function getThisName(){
return getFunctionCallerName();
}
const functionName = getThisName();
expect(functionName).to.equal('getThisName');
});
it('should work with an anonymous function', () => {
const anonymousFn = function (){
return getFunctionCallerName();
};
const functionName = anonymousFn();
expect(functionName).to.equal('anonymousFn');
});
it('should work with an anonymous function', () => {
const fnName = (function (){
return getFunctionCallerName();
})();
expect(/\/util\/functions\.js/.test(fnName)).to.eql(true);
});
});
Обратите внимание, что третий тест будет работать, только если тест находится в / UTIL / функции
Я думаю, проблема в следующем коде -
radioButton1.Checked = bool.TryParse(temp[0], out tempBool);
radioButton2.Checked = bool.TryParse(temp[1], out tempBool);
bool.TryParse
всегда будет возвращать true, если он сможет успешно разобрать первый параметр в значение bool. Что вам нужно сделать.
bool tempBool_1 = false, tempBool_2 = false;
if(bool.TryParse(temp[0], out tempBool_1))
{
radioButton1.Checked = tempBool_1;
}
else
{
// handle parsing error.
}
if(bool.TryParse(temp[0], out tempBool_2))
{
radioButton2.Checked = bool.TryParse(temp[1], out tempBool_2);
}
else
{
// handle parsing error.
}
radioButton1.Checked = bool.TryParse(temp[0], out tempBool);
наradioButton1.Checked = Convert.ToBoolean(temp[0]);
, и он работает – Aziks 13 July 2018 в 06:46Convert.ToBoolean()
будет генерировать исключение, если он не сможет проанализировать значение. – Kedar Rudre 13 July 2018 в 06:48