Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 试图运行QUnit测试,但找不到明确定义的函数_Javascript_Typescript_Karma Jasmine_Qunit - Fatal编程技术网

Javascript 试图运行QUnit测试,但找不到明确定义的函数

Javascript 试图运行QUnit测试,但找不到明确定义的函数,javascript,typescript,karma-jasmine,qunit,Javascript,Typescript,Karma Jasmine,Qunit,我在正在运行的一个测试中修改了这个示例 https://embed.plnkr.co/plunk/OJpuhX 在测试中,导入功能失败了,但我找到了解决方法 下面是该示例中的代码块: index.html <!DOCTYPE html> <html> <head> <link data-require="qunit@*" data-semver="1.17.1" rel=

我在正在运行的一个测试中修改了这个示例

https://embed.plnkr.co/plunk/OJpuhX
在测试中,导入功能失败了,但我找到了解决方法

下面是该示例中的代码块:

index.html

    <!DOCTYPE html>
    <html>

    <head>
        <link data-require="qunit@*" data-semver="1.17.1" rel="stylesheet"
            href="http://code.jquery.com/qunit/qunit-1.17.1.css" />
        <script data-require="qunit@*" data-semver="1.17.1" src="http://code.jquery.com/qunit/qunit-1.17.1.js"></script>
    </head>


    <body>
        <div id="qunit"></div>
        <div id="qunit-fixture"></div>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
        <script src="hello.js"></script>
        <script src="hello.test.js"></script>
    </body>

    </html>
你好,test.js

export class showAlert {
    static msg() {
        alert('Hello World!');
        // retmsg = 'Hello World!'
        // return retmsg;
    }
}
import ('hello.ts');

QUnit.test("hello test", function (assert) {
    assert.ok(hello.hello() === 'Hello World!', 'Passed!');
});
hello.ts(以前是hello.js),如果由于导入而导致的ts无法在模块外工作,则无法导入该文件

var hello: any;

import { showAlert as _alert } from './add';

   hello = function hello() {
      alert('MakeTest: ' + _alert);
      return 'Hello World!';
   };
   alert('Hello var: ' + hello);
我经常遇到的错误是:

PS C:\Users\pborregg\repos\wwwroot\acquisition-global-components\src> npm test

> acquisition-aem-global-components@1.0.0 test C:\Users\pborregg\repos\wwwroot\acquisition-global-components\src
> karma start

START:
19 05 2021 13:31:35.547:WARN [filelist]: Pattern "C:/Users/pborregg/repos/wwwroot/acquisition-global-components/src/hello.js" does not match any file.
19 05 2021 13:31:35.600:INFO [karma-server]: Karma v6.3.2 server started at http://localhost:9876/
19 05 2021 13:31:35.643:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
19 05 2021 13:31:35.704:INFO [launcher]: Starting browser Chrome
19 05 2021 13:31:40.045:INFO [Chrome 90.0.4430.212 (Windows 10)]: Connected on socket lmNGV4w5POgtxbWPAAAB with id 46008113
× hello test
Finished in 0.018 secs / 0.003 secs @ 13:31:40 GMT-0700 (Pacific Daylight Time)

SUMMARY:
√ 0 tests completed
× 1 test failed

FAILED TESTS:
× hello test
Chrome 90.0.4430.212 (Windows 10)
Died on test #1     at hello.test.js:12:7: hello is not defined
ReferenceError: hello is not defined
  at Object.<anonymous> (hello.test.js:13:15)
  at runTest (C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:2251:37)
  at Test.run (C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:2239:9)
  at C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:2461:16
  at processTaskQueue (C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:1849:33)
  at C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:1853:13
  npm ERR! Test failed.  See above for more details.
PS C:\Users\pborregg\repos\wwwroot\acquisition global components\src>npm测试
>收购aem全球-components@1.0.0测试C:\Users\pborregg\repos\wwwroot\acquisition global components\src
>因果报应
开始:
19 05 2021 13:31:35.547:警告[文件列表]:模式“C:/Users/pborregg/repos/wwwroot/acquisition global components/src/hello.js”与任何文件都不匹配。
19 05 2021 13:31:35.600:信息[karma服务器]:karma v6.3.2服务器在启动http://localhost:9876/
19 05 2021 13:31:35.643:INFO[launcher]:在不限制并发的情况下启动浏览器Chrome
19 05 2021 13:31:35.704:信息[启动器]:启动浏览器Chrome
19 05 2021 13:31:40.045:信息[Chrome 90.0.4430.212(Windows 10)]:连接在id为46008113的插槽lmNGV4w5POgtxbWPAAAB上
×你好测试
格林尼治标准时间13:31:40-0700(太平洋夏令时)在0.018秒/0.003秒内完成
总结:
√ 已完成0项测试
×1试验失败
失败的测试:
×你好测试
Chrome 90.0.4430.212(Windows 10)
在hello.test.js:12:7:hello未定义时死于测试1
ReferenceError:未定义hello
反对。(你好,test.js:13:15)
运行测试时(C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:2251:37)
在Test.run(C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:2239:9)
在C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:2461:16
在processTaskQueue(C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:1849:33)
在C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:1853:13
npm错误!测试失败。请参见上文了解更多详细信息。
注意:

PS C:\Users\pborregg\repos\wwwroot\acquisition-global-components\src> npm test

> acquisition-aem-global-components@1.0.0 test C:\Users\pborregg\repos\wwwroot\acquisition-global-components\src
> karma start

START:
19 05 2021 13:31:35.547:WARN [filelist]: Pattern "C:/Users/pborregg/repos/wwwroot/acquisition-global-components/src/hello.js" does not match any file.
19 05 2021 13:31:35.600:INFO [karma-server]: Karma v6.3.2 server started at http://localhost:9876/
19 05 2021 13:31:35.643:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
19 05 2021 13:31:35.704:INFO [launcher]: Starting browser Chrome
19 05 2021 13:31:40.045:INFO [Chrome 90.0.4430.212 (Windows 10)]: Connected on socket lmNGV4w5POgtxbWPAAAB with id 46008113
× hello test
Finished in 0.018 secs / 0.003 secs @ 13:31:40 GMT-0700 (Pacific Daylight Time)

SUMMARY:
√ 0 tests completed
× 1 test failed

FAILED TESTS:
× hello test
Chrome 90.0.4430.212 (Windows 10)
Died on test #1     at hello.test.js:12:7: hello is not defined
ReferenceError: hello is not defined
  at Object.<anonymous> (hello.test.js:13:15)
  at runTest (C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:2251:37)
  at Test.run (C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:2239:9)
  at C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:2461:16
  at processTaskQueue (C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:1849:33)
  at C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:1853:13
  npm ERR! Test failed.  See above for more details.
要亲自尝试,请将所有内容放在同一文件夹中

谢谢你的帮助