Tag: jestjs

如何利用请求集成testingasynchronousKoa节点API

我正在使用Koa2和Request对第三方进行RESTful API调用来处理我的第一个真实世界的Node项目。 Koa服务本身是相对简单的,但我正在尝试使用Jest编写一个集成testing。 我已经find使用Supertest / Superagent的Jest的例子 ,但我无法find如何使用只有Jes​​t和Request作为http客户端编写等效testing。 下面是Jest / Supertest的例子 const request = require('supertest'); const app = require('../../src/app') describe('Test the root path', () => { test('It should response the GET method', async () => { const response = await request(app).get('/'); expect(response.statusCode).toBe(200); }); }) 似乎我应该可以使用请求做超supertest / superagent在这里做的相同的事情,但我找不到任何例子。 感谢您的build议!

Jest 20 + Webpack 2 + React 15 – 图像导入问题

我试图testing显示图像的React组件,但我得到以下错误: FAIL test/image.test.js ● Test suite failed to run [Obfuscated…]/assets/images/sample.png:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){ ^ SyntaxError: Invalid or unexpected token at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17) at Object.<anonymous> (src/components/image.js:3:18) at Object.<anonymous> (test/image.test.js:3:14) 该组件非常简单 import React from 'react'; import { Component } from 'react'; import image from '../assets/images/sample.png'; export default class Image extends Component { render() { return ( <div > <img […]

当代码在node_modules中链接时,configurationjest代码覆盖范围

我正试图重构一个Node项目,使用Jest进行testing。 最初,我把所有的.js和.test.js文件都放在同一个目录下,而且所有的东西都在这个世界上, 也就是说 ,我所期望的jest –coverage 就是 jest –coverage 。 我已经改变了我的目录结构,testing工作,但我的覆盖面报告没有。 这里是我的目录结构,编辑删除node_modules 除符号链接到我的lib文件夹。 我正在按照这个暗示 requiring我的模块通过符号链接。 ❯ tree . ├── README.md ├── build │ └── index.js ├── jest.config.js ├── lib │ ├── path.js │ ├── pen.js │ ├── section.js │ ├── sprite.js │ └── utilities.js ├── node_modules │ ├── itch <= symlink to my `lib` folder ├── […]

如何用babel-jest和节点检查器来debugginges6testing

我不知道如何生成源映射来debugging节点检查器上的jesttesting,现在我正在使用这个命令,但正在生成传输代码: node –debug-brk ./node_modules/.bin/jest –runInBand

使用TFS 2015运行Jestunit testing

有没有人试图整合玩笑unit testing与TFS 2015? 我试图使用Chutzpahtesting适配器( https://visualstudiogallery.msdn.microsoft.com/f8741f04-bae4-4900-81c7-7c9bfb9ed1fe?SRC=VSIDE ),但它无法识别开玩笑。 我收到下面的错误: 无法findvariablesJEST 当我通过“npmtesting”运行unit testing时,我得到了结果。 但是为了与TFS 2015集成,我需要一个可以运行Jestunit testing的testing运行器,以便我可以与TFS 2015提供的vstest.console.exe一起运行unit testing,因此它可以pipe理构build结果​​并在构build中发布结果总结报告。 任何帮助,将不胜感激!! 任何可以使用下面的命令运行testing的testing运行器应该可以工作(考虑到系统上安装了VS 2015):“C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ CommonExtensions \ Microsoft \ TestWindow \ vstest.console .exe“”\ test.js“/ UseVsixExtensions:true

如何在不使用Jesttesting运行器的情况下使用Jest的断言库?

Jest创造了这个全球性的expect 。 我怎样才能使用, 而不使用他们的testing赛跑者? 即,我必须input/要求什么?

如何使用iron-node来debugging玩笑unit testing?

要运行我的UT,我运行命令: BABEL_JEST_STAGE=0 jest 我如何使用iron-node来debugging我的unit testing? 顺便说一句,我的package.json有一个标准的笑话configuration: "jest": { "scriptPreprocessor": "<rootDir>/node_modules/babel-jest", "testFileExtensions": [ "es6", "js" ], "moduleFileExtensions": [ "js", "json", "es6" ], "unmockedModulePathPatterns": [ "react" ] }

在更新到npm 3.3.12之后,使用Jest进行unit testing时出错

我最近更新了我的项目到节点5.1.0,npm 3.3.12,并更新了我所有的依赖…现在我正在对付一堆错误! 最初我在这个问题上有同样的错误: https : //github.com/facebook/jest/issues/554 ,很容易修复。 Bur现在我得到这个: 警告:React.createElement:types不应该是null,undefined,boolean或number。 它应该是一个string(对于DOM元素)或ReactClass(对于复合组件)。 和 错误:不变违规:元素types无效:期望一个string(对于内置组件)或一个类/函数(对于复合组件),但得到:对象。 我有这在我的package.json: "jest": { "collectCoverage": true, "testRunner": "./node_modules/jest-cli/src/testRunners/jasmine/jasmine2", "scriptPreprocessor": "./node_modules/babel-jest", "unmockedModulePathPatterns": [ "./node_modules/es6-promise", "./node_modules/events", "./node_modules/fbjs", "./node_modules/flux", "./node_modules/history", "./node_modules/immutable", "./node_modules/lodash", "./node_modules/moment", "./node_modules/react", "./node_modules/react-addons-pure-render-mixin", "./node_modules/react-addons-test-utils", "./node_modules/react-d3", "./node_modules/react-dom", "./node_modules/react-modal", "./node_modules/react-router", "./node_modules/whatwg-fetch" ] } 我的testing的相关部分是: var ImageGallery = require('../../../app/components/image-gallery/image-gallery'); imageGalleryComponent = TestUtils.renderIntoDocument( <ImageGallery items={items} onSlide={onSlideMock} lazyLoad={false} showBullets={true} showThumbnails={true} […]

让Jest在testing时忽略无用的导入

testing组件 我正在尝试对Jest的反应组件进行一些非常简单的testing。 我遇到了问题,因为这个行在我的组件文件的顶部 import {} from './style.less'; 这里的input不需要testing,理想情况下可以忽略testing。 [npmtesting]的结果 当通过npm test运行npm test我得到响应 FAIL testing /app_test.js●运行时错误SyntaxError:意外的标记{在文件'client / components / app / style.less'中。 确保预处理器设置正确,并确保“preprocessorIgnorePatterns”configuration正确: http : //facebook.github.io/jest/docs/api.html#preprocessorignorepatterns-array-string如果您当前正在设置Jest或修改你的预处理器,试试jest –no-cache 。 预处理器:node_modules / jest-css-modules。 Jest试图执行以下预处理代码://一些无代码 但是,如果我注释掉更less的导入行,我的testing运行正常。 题 我怎样才能让开玩笑跳过这一行代码或忽略此导入?

笑话 – 有没有办法检查testing覆盖率的百分比?

我用下面的命令来运行我的testing,并得到一个覆盖报告: jest –coverage 现在我想检查我的脚本文件中覆盖百分比是否超过90%。 我该怎么办 ?