Tag: jest

错误:“ReactFifteenAdapter.js”中找不到模块'react-dom / test-utils'“,对于jest-styled-componentsconfiguration,使用了React 15.4.1

仅在使用React版本15.4.1configurationJest-Styled组件时出错。 我们不会升级React版本。 我们只需要configuration上面的反应版本。 我没有安装以下软件包 – 开玩笑风格组件 反应试验渲染器 酶到JSON 酶 – 接合体反应的-15 的package.json { "name": "app", "version": "0.0.1", "description": "", "engines": { "npm": ">=3", "node": ">=5" }, "scripts": { "analyze:clean": "rimraf stats.json", "preanalyze": "npm run analyze:clean", "analyze": "node ./internals/scripts/analyze.js", "extract-intl": "babel-node –presets latest,stage-0 — ./internals/scripts/extract-intl.js", "npmcheckversion": "node ./internals/scripts/npmcheckversion.js", "preinstall": "npm run npmcheckversion", "postinstall": "npm run build:dll", […]

笑npm脚本的正则expression式

我想执行2个不同的testing环境, 一个用于integration tests ,另一个用于unit tests 。 文件夹结构是这样的: __tests__/ut/p/a/t/h/file.test.ts __tests__/it/p/a/t/h/file.test.ts 我拿出了这些正则expression式: (__tests__/ut/.*\.test)\.(tsx?|ts?)$ (__tests__/it/.*\.test)\.(tsx?|ts?)$ 我的脚本如下所示: "test:ut": "jest \"(__tests__/ut/.*\\.test)\\.(tsx?|ts?)$\"", "test:it": "jest \"(__tests__/it/.*\\.test)\\.(tsx?|ts?)$\"", 但是当我运行yarn test:ut我得到: yarn run v1.3.2 $ jest "(__tests__/ut/.*\.test)\.(tsx?|ts?)$" No tests found In /home/dev/sample 20 files checked. testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) – 0 matches testPathIgnorePatterns: /node_modules/ – 20 matches Pattern: (__tests__/ut/.*\.test)\.(tsx?|ts?)$ – 0 matches Done in 0.49s. 虽然,如果我在jsonconfiguration文件中使用相同的模式,它工作。 我想我是如何执行这个jest […]

将传递的属性值存储在另一个函数中使用的variables中

题.. 我想传递我在HTTP POST请求中使用的属性值,所以我可以在另一个testing中使用它。 const device = `28` + (new Date().getTime()) describe('register device', () => { test('create device registration', async () => { try { const registerDevice= await axios.post(`${baseUrl}register`, { deviceId: (`${deviceId}`), platformId: 'ios', osVersion: '11.0' }, { timeout, headers: { 'Authorization': `Bearer ${tokenGenerator.generateAuthToken({ name: 'namehere' })}` } }) expect(registerDevice.status).toBe(200) }) }) 我想从上面的POST请求传递给deviceId使用相同的值,所以我可以把它放在我的下一个POST请求的负载上。任何build议都会有帮助。 谢谢!

npm在CircleCI上testing意外的行为

在CircleCI的支持下,提出了我面临的问题和答案。 我有安装testing,并在本地运行时,他们都跑了,并通过。 然而,当CircleCI运行它们时,出现了错误。 第一个是usage of let and const are not allowed outside of 'use strict' mode 。 我修改了罪魁祸首的文件,然后重新build立。 然后我得到一个奇怪的错误: Unexpected token { 我可以发现代码本身没有错。 请参阅下面的答案。

Jest – 尝试在Node Jstesting中模拟asynchronous等待

我正在尝试使用Jest进行我的Node Jstesting(特别是AWS的Lambda),但是我很难模拟asynchronous等待function。 我正在使用babel-jest和jest-cli。 以下是我的模块。 我得到第一个console.log,但第二个console.log返回未定义和我的testing崩溃。 任何想法如何实现这个? 以下是我的模块: import {callAnotherFunction} from '../../../utils'; export const handler = async (event, context, callback) => { const {emailAddress, emailType} = event.body; console.log("**** GETTING HERE = 1") const sub = await callAnotherFunction(emailAddress, emailType); console.log("**** Not GETTING HERE = 2", sub) // **returns undefined** // do something else here callback(null, {success: true, […]

当代码在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 ├── […]

没有testing发现运行与咕噜玩笑

我试图用一个咕task任务来运行我的笑话,但这样做,我得到没有testing发现消息在控制台。 PFB的设置相同: gruntfile.js片段: exec: { jest: 'node node_modules/jest/bin/jest -u –config="test/unit/jest/jest.conf.json"' } jest.conf.json: { "testEnvironment": "jsdom", "setupTestFrameworkScriptFile": "./enzyme.setup.js", "testResultsProcessor": "jest-teamcity-reporter" } 酶.setup.js: import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-15.4'; configure({ adapter: new Adapter() }); 运行grunt exec任务的控制台显示如下: No tests found In C:\Vishal\UI\Jest-Grunt\proj\test\unit\jest 3 files checked. testMatch: .js?(x),**/?(*.)(spec|test).js?(x) – 0 matches testPathIgnorePatterns: \\node_modules\\ – 3 […]