我试图将jest添加到我的typescript项目中进行测试,但是当我运行jest时,它总是给我这个错误 ● Test suite failed to run
Cannot find module 'fs/promises' from 'src/path/to/file'
Require stack:
src/path/to/file
test/test.ts
> 3 | import fsp from 'fs/promises';
at Resolver.resolveMo
尝试用Jest测试角服务,得到了以下错误:
[$injector:nomod] Module 'superag' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
我如何模拟我的模块'superag‘并使其可用于mathService
我是否必须导入每个测试都带有模块声明的app.js文件?
我正在尝试使用Node运行一个Javascript文件,以便将博客更新发布到Tumblr。
到目前为止,在我的main.js文件中,我有以下内容:
// Tumblr Information
var tumblr = require('./vendor/tumblr');
tumblr.request(require('request'));
var Blog;
var jq = require('./vendor/jquery-1.11.1.min');
var reqq = require('./vendor/require'
注意:我将src/nod_modules文件夹中的所有代码直接移动到src文件夹中,并按照以下短线程:删除src/node_modules,从而修复了这个问题。
我使用的是创建-反应-应用程序和运行Jest有困难。
当我试图将任何一个响应组件导入到我的测试文件中时,当我yarn test时会得到一个错误。
Test suite failed to run
.../src/node_modules/common/ErrorMessage.js:1
({"Object.<anonymous>":function(
module,exports,require,__d
我使用npm安装了puppeteer,然后在尝试编译它时,出现了以下错误:
This dependency was not found:
* ws in ./node_modules/puppeteer/lib/WebSocketTransport.js
To install it, you can run: npm install --save ws
These relative modules were not found:
* ./types/other in ./node_modules/puppeteer/node_modules/mime/index.js
* ./typ
我想模拟一个模块进行测试。一切正常,但我必须将相同的代码复制/粘贴到每个测试文件中。我怎样才能使它更易于维护?
(这是在TypeScript项目中使用Babel和Next.js。)
生产代码如下所示:
import { useRouter } from 'next/router';
// Then call the hook in a React component:
const router = useRouter();
测试代码:
// I need to access these mocks in the tests
const mockRouterPush = j
在运行Jest测试用例时,将D3与Jest和with相结合,将面临问题。
测试套件无法运行
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "n
我正在尝试使用Jest来测试我的Svelte项目,我读到的所有内容都表明我需要包含svelte-jester,以便将我的Svelte代码转换为Jest可以处理的东西(我想是CommonJS?)。这似乎工作得很好,除了我将Lodash导入到我的一些Svelte组件中,但是Jest在运行其测试时报告说Lodash是未定义的。(在浏览器环境中,一切似乎都像预期的那样工作。)
为了演示这个问题,我复制并略微修改了测试库网站上的一个示例:
// Comp.svelte
<script>
import _ from 'lodash';
export let name
我有一个TypeScript模块(应该是无关紧要的,因为我认为这也会影响JS ),我正在尝试测试我有的一个模块。该模块从外部文件导入大量数据,并根据a变量选择应返回的数据。
我正在尝试运行一些测试,其中我更新了变量,重新require了模块,并在一个文件中运行了进一步的测试。但我的问题是文件的require只运行一次。我猜它被缓存了。有没有可能告诉Jest的require函数不缓存或在测试之间清除缓存?
下面是我想要实现的一些精简代码:
module.ts
import { getLanguage } from "utils/functions";
import * as m
我有一个导入组件的测试,该组件反过来导入一个助手文件,该文件使用window对象提取查询字符串参数。我得到以下关于window的错误
FAIL src/js/components/__tests__/Controls.test.jsx
● Test suite failed to run
ReferenceError: window is not defined
Controls.jsx
import { Unwrapped as Controls } from '../Controls'
describe('<MyInterestsControls
以下JavaScript代码工作:
let Color = require('color');
class Example {
its_not_easy_being_green() {
return Color('green');
}
}
test('It is not easy being green', () => {
expect(new Example().its_not_easy_being_green()).toBeDefined();
})
npx jest给我买了一个绿色酒吧。
$
Jest使用describe、it和expect,而不必对它们进行require。这是可以的,因为如果您有一个名为test.spec.js的测试文件,则永远不会通过发出命令node test.spec.js直接执行它。
我想使用节点作为标准的js文件来执行它,而不必使用jest的cli或npm test。有可能这样做吗?
例如,我会转换以下文件:
// taken from documentation
const user = require('./users.js')
it('works with promises', () => {
expect.
我刚刚开始使用Jest测试框架,虽然直接的单元测试工作良好,但我在测试其模块(通过babel+webpack的ES模块)中需要HTML文件的任何组件时都遇到了大量问题。
下面是一个示例:
import './errorHandler.scss';
import template from './errorHandler.tmpl';
class ErrorHandler {
...
我正在加载特定于组件的SCSS文件,它是我在Jest的package.json配置中设置的,以返回一个空对象,但是当Jest尝试运行import template from
我对我的React组件进行了以下测试
var React = require('react/addons');
var Router = require('react-router').Router;
var Route = require('react-router').Route;
var Link = require('react-router').Link;
TestUtils = React.addons.TestUtils;
describe('Navigation', function() {
v