gpt4 book ai didi

javascript - 业力 + Mocha + 应该 v7 不工作 - 应该是未定义的

转载 作者:行者123 更新时间:2023-12-03 09:28:32 26 4
gpt4 key购买 nike

我正在尝试配置 karma + mocha + Should,但我必须缺少一些东西,因为 should 在我的测试中未定义。

根据plugin documentation ,唯一需要遵循的步骤是:

1.- Add should to frameworks and karma-should to plugins keys in your karma configuration:

module.exports = function(config) {
config.set({
frameworks: ['mocha', 'should'],
plugins: ['karma-should']
});
};

All should assertions are available in the tests

这是我的配置:

package.json

"devDependencies": {
"karma": "^0.13.3",
"karma-chrome-launcher": "^0.2.0",
"karma-firefox-launcher": "^0.1.6",
"karma-mocha": "^0.2.0",
"karma-phantomjs-launcher": "^0.2.0",
"karma-requirejs": "^0.2.2",
"karma-should": "0.0.1",
"mocha": "^2.2.5",
"should": "^7.0.2",
}

karma.conf.js

config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'should'],

plugins: ['karma-mocha',
'karma-should',
'karma-chrome-launcher',
'karma-firefox-launcher'],

simpleTest.js

describe('theAnswer()', function() {
it('should be 42', function() {
theAnswer().should.be.exactly(42);
});
});


function theAnswer() {
return 42;
}

当我运行 karma start 时,我得到:

Firefox 39.0.0 (Windows 7 0.0.0) theAnswer() should be 42 FAILED
theAnswer(...).should is undefined

知道为什么吗?

最佳答案

由于 should 7.x.x 中的包更改,插件实现似乎存在问题:

有一个针对此的开放拉取请求: https://github.com/seegno/karma-should/pull/1

当前插件版本(0.0.1)最高可达 6.x.x。

编辑:最新的 karma-should 插件版本 (1.0.0) 纠正了此问题。

关于javascript - 业力 + Mocha + 应该 v7 不工作 - 应该是未定义的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31586480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com