【问题标题】:Sample Extjs5 App for Unit testing with Jasmine and Karma-runner使用 Jasmine 和 Karma-runner 进行单元测试的示例 Extjs5 应用程序
【发布时间】:2014-10-17 10:45:46
【问题描述】:
我是 Extjs5 的新手,正在尝试使用 karma-runner 运行 jasmine 单元测试用例。虽然我成功地能够从 Ext4.2 应用程序做到这一点,但同样的过程不适用于 Extjs5。
我已经查看了它,但没有任何有用的链接
如果有人已经为 Ext5 应用程序执行过,请分享代码。
非常感谢任何帮助。
谢谢
塔帕斯维尼
【问题讨论】:
标签:
unit-testing
karma-runner
karma-jasmine
extjs5
【解决方案1】:
诀窍是让所需的 ExtJS 类在您开始测试之前正确加载。
确保在 karma.conf.js 中包含以下内容
// We need to add an element with the ID 'appLoadingIndicator' because [app.js].launch() is expecting it and tries to remove it
// Karma normally starts the tests right after all files specified in 'karma.config.js' have been loaded
// We only want the tests to start after Sencha Touch/ExtJS has bootstrapped the application
// 1. We temporary override the '__karma__.loaded' function
// 2. When Ext is ready we call the '__karma__.loaded' function manually
var karmaLoadedFunction = window.__karma__.loaded;
window.__karma__.loaded = function () {
};
bootstrapExtJS(); // Create this function to add anything that is not included in your class definition requires and you need to require explicitly
Ext.onReady(function () {
window.__karma__.loaded = karmaLoadedFunction;
window.__karma__.loaded();
});
让我知道它是否适合你。