在为Cordova应用程序运行茉莉测试时,我遇到了一个问题:我有一个html页面(Jasmine 2.4 SpecRunner.html),其中的<head>脚本(插件,服务,控制器等)要加载,最后一个包含<head>中的文件是测试文件。在主体中,我有一个deviceready事件侦听器。但是,当我针对android模拟器运行测试时,我的测试总是在deviceready之前执行,并且看不到插件(即错误“未定义设备”)。

所以问题是:如何在deviceready事件之后完全延迟测试文件的执行?

我的SpecRunner.html:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <meta name="msapplication-tap-highlight" content="no" />
        <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
        <title>SportsWellness</title>


        <script src="scripts/winstore-jscompat.js"></script>

    <link rel="shortcut icon" type="image/png" href="jasmine/lib/jasmine-2.4.1/jasmine_favicon.png">
    <link rel="stylesheet" href="jasmine/lib/jasmine-2.4.1/jasmine.css">

    <!-- Jasmine Modules -->

    <script src="jasmine/lib/jasmine-2.4.1/jasmine.js"></script>
    <script src="jasmine/lib/jasmine-2.4.1/jasmine-html.js"></script>
    <script src="jasmine/lib/jasmine-2.4.1/boot.js"></script>

    <!-- SportsWellness references -->
    <link rel="stylesheet" href="css/app.css" />

    <!-- AngularJS modules -->
    <script src="libs/angular.min.js"></script>
    <script src="libs/angular-resource.min.js"></script>
    <script src="libs/angular-ui-router.js"></script>
    <script src="libs/angular-touch.min.js"></script>
    <script src="libs/angular-animate.min.js"></script>
    <script src="libs/angular-mocks.js"></script>

    <!-- Cordova reference, this is added to app when it's built. -->
    <script src="cordova.js"></script>

    <!-- Include Application scripts -->
    <script type="text/javascript" src="js/app.js"></script>
    <script type="text/javascript" src="js/router.js"></script>
    <script type="text/javascript" src="js/platformOverrides.js"></script>

    <!-- Include Controllers-->
    <!-- Script tags  -->

    <!-- Include Services -->
    <!-- Script tags  -->

    <!-- Include Directives -->
    <!-- Script tags  -->

    <!-- Include Configuration Scripts -->
    <!-- Script tags  -->

    <!-- Include specs to run -->
    <script src="tests/ServicesTests/ReminderService.spec.js"></script>

</head>
    <body>
    <script type="application/javascript">
        document.addEventListener('deviceready', function () {
            navigator.splashscreen.hide();
        }, false);
    </body>
    </html>

最佳答案

解决方案没有我想要的那么漂亮,但是我更改了jasmine / boot.js文件,并用window.onload替换了document.addEventListener('deviceready', ...)函数

10-04 15:47