javascript - Kotlin Javascript 中的 ReferenceError : ok is not defined at QUnitAsserter. assertTrue

标签 javascript unit-testing kotlin

Kotlin 版本 1.0.x-1.1.0 支持开箱即用的单元测试 QUnit但是当我加载测试时它会抛出此异常:

ReferenceError: ok is not defined
    at QUnitAsserter.assertTrue_4mavae$ (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/lib/kotlin-test-js.js:50:5)
    at assertTrue (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/lib/kotlin-test-js.js:93:27)
    at QUnitAsserter.assertTrue_o10pc4$ (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/lib/kotlin-test-js.js:47:5)
    at QUnitAsserter.Asserter.assertEquals_lzc6tz$ (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/lib/kotlin-test-js.js:182:10)
    at assertEquals (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/lib/kotlin-test-js.js:108:20)
    at AppTest.myFirstTest (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/app_test.js:17:5)
    at Object.<anonymous> (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/app_test.js:29:21)

这是我的测试类:

import org.junit.Test
import kotlin.test.assertEquals

class AppTest {

    @Test fun myFirstTest() {
        assertEquals(1, 1, "Test in test folder works")
    }
}

这是加载测试的 html 代码:

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Fibonacci Counter</title>
        <link rel="stylesheet" href="css/app.css">
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.1.1.css">
    </head>
    <body>
        <div id="qunit"></div>
        <div id="qunit-fixture"></div>
        <footer id="info">
            <p>Placeholder</p>
        </footer>
        <span id="text"></span>
        <script src="external_libs/jquery-3.1.1.min.js"></script>
        <script src="https://code.jquery.com/qunit/qunit-2.1.1.js"></script>
        <script src="lib/kotlin.js"></script>
        <script src="lib/kotlin-test-js.js"></script>
        <script src="app_main.js"></script>
        <script src="app_test.js"></script>
    </body>
</html>

最佳答案

问题出现在QUnit 2.1.1版本中,通过使用版本1.23.1解决了问题。

这是加载修复后的测试的 html 代码:

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Fibonacci Counter</title>
        <link rel="stylesheet" href="css/app.css">
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-1.23.1.css">
    </head>
    <body>
        <div id="qunit"></div>
        <div id="qunit-fixture"></div>
        <footer id="info">
            <p>Placeholder</p>
        </footer>
        <span id="text"></span>
        <script src="external_libs/jquery-3.1.1.min.js"></script>
        <script src="https://code.jquery.com/qunit/qunit-1.23.1.js"></script>
        <script src="lib/kotlin.js"></script>
        <script src="lib/kotlin-test-js.js"></script>
        <script src="app_main.js"></script>
        <script src="app_test.js"></script>
    </body>
</html>

关于javascript - Kotlin Javascript 中的 ReferenceError : ok is not defined at QUnitAsserter. assertTrue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42538010/

相关文章:

javascript - Visual Studio Code 在多行上对齐函数参数

javascript - 在循环之前定义数组的长度是一种好习惯吗?

javascript - 如何阅读和理解 ExtJS 源代码?

c# - 单元测试在全部运行时失败,但在单独运行时通过

kotlin - Kotlin-将函数数组作为函数的参数传递

android - java.lang.IllegalArgumentException : On Android P, 类注入(inject)只能应用于BaseDexClassLoader

javascript - Angular.Js 使用其他 3 个输入的总和动态更新输入

java - Maven 使用 AnnotationProcessor 构建,解析 src/main/java 中的文件并生成源代码到 generated-test-sources/test-annotations

kotlin - 在调用主要构造函数之前,如何运行代码?

asp.net-mvc - ASP.NET MVC : Unit testing controllers that use UrlHelper