Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.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

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 使用摩卡和x2B测试承诺是否被拒绝;柴如约';我好像不工作_Javascript_Typescript_Mocha.js_Chai_Chai As Promised - Fatal编程技术网

Javascript 使用摩卡和x2B测试承诺是否被拒绝;柴如约';我好像不工作

Javascript 使用摩卡和x2B测试承诺是否被拒绝;柴如约';我好像不工作,javascript,typescript,mocha.js,chai,chai-as-promised,Javascript,Typescript,Mocha.js,Chai,Chai As Promised,我有一个异步函数,它依赖于另一个异步函数,我正在测试当url错误时它是否会抛出错误,它确实会抛出错误,并且它在控制台上 但是测试一直失败,但是我编写了语法。我完全不知道该怎么写,我在这些废话上浪费了太多时间 expect(GetSecret('', 'test-secret')).to.eventually.throw( 'TypeError: Only absolute URLs are supported', ); expect(GetSecret('', 'test

我有一个异步函数,它依赖于另一个异步函数,我正在测试当url错误时它是否会抛出错误,它确实会抛出错误,并且它在控制台上

但是测试一直失败,但是我编写了语法。我完全不知道该怎么写,我在这些废话上浪费了太多时间

expect(GetSecret('', 'test-secret')).to.eventually.throw(
      'TypeError: Only absolute URLs are supported',
    ); 

expect(GetSecret('', 'test-secret')).to.eventually.throw;
expect(GetSecret('', 'test-secret')).to.eventually.be.rejected;
这是我尝试过的几种方法,但每次都有相同的结果。 我也试着
等待GetSecret(''
…在每一个可能的组合中使用它们,但是,结果是一样的

我的版本:

    "@types/mocha": "^5.2.7",
    "@types/chai-as-promised": "^7.1.2",
    "chai": "2.1.2",
    "chai-as-promised": "^7.1.1", 

然后导入:

import { expect } from 'chai';

使用插件需要你告诉chai使用它,你可以这样做:

const chai = require('chai');
chai.use(require('chai-as-promised'));
现在,您可以使用附加功能,在本例中,
最终

const expect = chai.expect;

return expect(returnsAPromise()).to.eventually.equal(someValue);

您是否设置了chai来使用插件?
chai.use(require('chai-as-associated'))
你能用
GetSecret
函数的代码编辑你的问题吗?@ChrisG我确实没有导入它,idk我是如何浏览了那一段文档的,如果你把它作为一个答案发布,我会把它标记为正确的。谢谢,这是有效的,除非摩卡没有通过测试,chai按照承诺需要
返回expect(…
啊,我完全忘了这是我能做的,哈!