我一直在爲我的Dojo窗口小部件創建一些測試來檢查布爾標誌是否正確設置。但是,我發現,因爲我已經改變了我的構造函數來傳入一個對象,以前運行測試似乎會影響後續測試。doh測試後dojo窗口小部件變量引用仍然保留
我已經嘗試銷燬拆卸方法中的小部件,但無論我如何做,值仍然存在。
任何人都可以建議我可能會做錯什麼嗎?
我的部件代碼:
var showControls = true;
return declare([WidgetBase, TemplatedMixin, _WidgetsInTemplateMixin], {
templateString: template,
constructor: function (params) {
this.showControls = (typeof params.showControls === "undefined" || typeof params.showControls != "boolean") ? this.showControls : params.showControls;
}
});
我的測試類是:
var customWidget;
doh.register("Test controls", [
{
name: "Test controls are not visible when set in constructor",
runTest: function() {
var params = { showControls: false };
customWidget = new CustomWidget(params);
doh.assertFalse(customWidget.getShowControls());
}
},
{
name: "Test controls are visible when set in constructor with string instead of boolean",
runTest: function() {
var params = { showControls: "wrong" };
customWidget= new CustomWidget(params);
doh.assertTrue(customWidget.getShowControls());
}
}
]);
所以,第一個測試通過,作爲showControls設置爲false,但第二次測試嘗試創建一個新的實例,其中構造函數將檢查該值是一個布爾值。然而,當我調試這個,它認爲showControls開始爲'假',不正確。
任何線索?
感謝
謝謝phusick,我試過你的建議,它的工作原理。我仍然試圖弄清楚它是如何工作的,說實話以及如何確保params對象中的屬性(在本例中爲params.showControls)實際上會在私有設置器中設置。 Dojo如何知道如何匹配這兩個? – IpponSolutions