我正在尝试开始学习最先进的Web开发学习React/Redux.
现在我坚持让测试运行.出于某种原因,jest失败了
Task :frontend:test
yarn jest v1.0.2
$ "/Users/gunnar/git/app.oakstair.se/frontend/node_modules/.bin/jest"
FAIL src/containers/App/App.test.js
? Test suite failed to run
ReferenceError: window is not defined
at Object.<anonymous> (config/polyfills.js:18:1)
at next (native)
at process._tickCallback (internal/process/next_tick.js:109:7)
Run Code Online (Sandbox Code Playgroud)
谷歌搜索了一段时间没有任何成功......
我正在使用Jest测试我的GraphQL api.
我正在为每个查询/突变使用单独的测试套装
我有2次测试(每一个在一个单独的测试套),其中我嘲笑一个函数(即,流星的callMethod
),其在突变使用.
it('should throw error if email not found', async () => {
callMethod
.mockReturnValue(new Error('User not found [403]'))
.mockName('callMethod');
const query = FORGOT_PASSWORD_MUTATION;
const params = { email: 'user@example.com' };
const result = await simulateQuery({ query, params });
console.log(result);
// test logic
expect(callMethod).toBeCalledWith({}, 'forgotPassword', {
email: 'user@example.com',
});
// test resolvers
});
Run Code Online (Sandbox Code Playgroud)
当console.log(result)
我得到
{ data: { forgotPassword: true } }
Run Code Online (Sandbox Code Playgroud)
这种行为不是我想要的,因为在.mockReturnValue
我抛出一个错误,因此期望result
有一个错误对象
然而,在此测试之前,另一个是运行
it('should throw an error if wrong credentials …
Run Code Online (Sandbox Code Playgroud) 在Sinon的存根中,恢复功能非常容易.
const stub = sinon.stub(fs,"writeFile",()=>{})
...
fs.writeFile.restore()
Run Code Online (Sandbox Code Playgroud)
我期待与Jest做同样的事情.我得到的最近的是这个丑陋的代码:
const fsWriteFileHolder = fs.writeFile
fs.writeFile = jest.fn()
...
fs.writeFile = fsWriteFileHolder
Run Code Online (Sandbox Code Playgroud) 我是新手,并试图在我的下面的代码中找出一些基本的东西
import * as actions from './IncrementalSearchActions';
describe('Incremental Search Actions', () => {
it('Should create an incremental search action')
});
Run Code Online (Sandbox Code Playgroud)
我对此有疑问/困惑
当我签入代码时,我想告诉Eclipse中的SVN忽略这些.在哪里可以设置此忽略列表:
.classpath
.project
.settings*
target
Run Code Online (Sandbox Code Playgroud) 对于移动设计,设计通常具有较小的标题字体。
Material-UI是否具有使版式响应的机制?
我看到默认主题具有在rems中定义的字体大小-这是否意味着仅减小基本字体大小就可以了?(这似乎不起作用,如果您想以不同的比率减少标题字体怎么办)。
我正在尝试编写一个函数,该函数将在引发对象常量时重新引入堆栈跟踪。(请参阅此相关问题)。
我注意到的是,如果将异步函数作为回调传递给另一个异步调用者函数,则如果调用者函数具有try / catch并捕获任何错误并抛出新的Error,则堆栈跟踪会丢失。
我已经尝试了几种方法:
function alpha() {
throw Error("I am an error!");
}
function alphaObectLiberal() {
throw "I am an object literal!"; //Ordinarily this will cause the stack trace to be lost.
}
function syncFunctionCaller(fn) {
return fn();
}
function syncFunctionCaller2(fn) { //This wrapper wraps it in a proper error and subsequently preserves the stack trace.
try {
return fn();
} catch (err) {
throw new Error(err); //Stack trace is preserved when it is synchronous.
}
} …
Run Code Online (Sandbox Code Playgroud) 我最近开始使用 lerna 来管理 monorepo,在开发中它运行良好。
Lerna 在我的各种包之间创建符号链接,因此像 'tsc --watch' 或 nodemon 这样的工具可以很好地检测其他包中的变化。
但是我在这种环境中创建 docker 镜像时遇到了问题。
假设我们有一个具有这种结构的项目:
root
packages
common ? artifact is a private npm package, this depends on utilities, something-specific
utilities ? artifact is a public npm package
something-specific -> artifact is a public npm package
frontend ? artifact is a docker image, depends on common
backend ? artifact is a docker image, depends on common and utilities
Run Code Online (Sandbox Code Playgroud)
在这种情况下,在开发中,一切都很好。我正在运行某种实时重新加载服务器,并且符号链接可以正常工作,因此依赖项可以正常工作。
现在假设我想从后端创建一个 docker 镜像。
我将介绍一些场景:
我ADD
在我的 Dockerfile 中打包.json,然后运行 npm install。 …
我很难学习如何使用笑话.我遇到的所有教程都教你如何测试渲染到dom的脚本,例如<App />
有或没有快照.其他教程讨论了如何使用输入模拟测试.但我似乎无法找到解释清楚的教程并提供我可以使用的示例.
例如,下面的脚本我有一个关于如何测试渲染部分的想法,但我不知道如何测试redux或其余的函数.
任何人都可以举例说明如何测试下面的脚本,我可以用它作为我需要在项目中测试的其余文件的参考吗?
import React, { Component } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import CustomSearch from '../Components/CustomSearch';
import CustomToolBar from '../Components/CustomToolBar';
import Table from '../Components/Table';
import InsertButton from '../Components/InsertButton';
import UserForm from './UserForm ';
import { fetchUsers, deleteUser } from '../../actions/users';
import setModal from '../../actions/modal';
import TableColumns from '../../constants/data/TableColumns';
class Users extends Component {
constructor(props) {
super(props);
this.onInsert = this.onInsert.bind(this);
this.onDelete = this.onDelete.bind(this);
this.onEdit = this.onEdit.bind(this);
this.props.fetchUsers({ accountId: this.props.userData.account.id, token: …
Run Code Online (Sandbox Code Playgroud) 我收到来自 API 的响应作为 json 响应。我正在用 python 编码后端。
前端团队需要来自原始 json 响应的信息来填充 UI,因此我们必须对 json 进行排序并使他们更容易获取信息。
现在我可以以特定格式订购 json 并推送到前端团队,或者我可以将原始 json 响应*传递给前端团队,让他们处理 json 的排序并进一步用于他们的 UI。
记住我的 json 文件大小是15MB。
哪个更快,更好的设计原则?
在后端处理然后推送到前端还是在前端处理?
jestjs ×5
javascript ×4
reactjs ×3
async-await ×1
devops ×1
docker ×1
eclipse ×1
eslint ×1
eslintrc ×1
graphql ×1
material-ui ×1
meteor ×1
mocking ×1
monorepo ×1
python-3.x ×1
stack-trace ×1
svn ×1
testing ×1
try-catch ×1
typography ×1
webpack ×1
yarnpkg ×1