我有一个弹性搜索服务器,我正在使用Jest客户端通过Java服务器访问,我正在寻找每次更新文档的多个字段的最佳方法.
到目前为止,我已经查看了文档,我发现有两种方法可以做到:
我的问题是如何知道Jest只通过脚本提供更新来更新整个文档?
这是删除文档和索引更新版本的最佳方法吗?
提前致谢,
我正在尝试使用特定的分析器和映射在ES中创建索引,使用JEST.我使用以下代码:
CreateIndex createIndex = new CreateIndex.Builder(indexName)
.settings(
ImmutableSettings.builder()
.loadFromClasspath(
"jestconfiguration.json"
).build().getAsMap()
).build();
JestResult result = client.execute(createIndex);
Run Code Online (Sandbox Code Playgroud)
这是jestconfiguration.java
{
"settings": {
"analysis": {
"analyzer": {
"second": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"synonym"
]
}
},
"filter": {
"synonym" : {
"type" : "synonym",
"synonyms" : [
"smart phone => smartphone"
]
}
}
}
},
"mappings": {
"index_type": {
"properties": {
"Name": {
"type": "string",
"analyzer": "second"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
虽然索引使用指定的"设置"正确装箱,但"映射"部分不起作用,我无法设置字段"名称"的映射.有人有想法吗?putmapping() JESt中是否有一种可以添加映射的东西?理想情况下,我希望能够动态设置field_name而不是.json文件.
Thnks
尝试加载具有动态导入代码的vueJs组件时,Jest会抛出错误.
零件:
<script>
const Modal = () => import(/* webpackChunkName: "Modal" */ "../pages/common/Modal.vue");
export default {
name: "TileEditModal",
components: {
Modal
},
data() {
return
},
methods: {
test() {
return true;
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
测试:
import TileEditModal from "./TileEditModal.vue"
Run Code Online (Sandbox Code Playgroud)
即使没有运行测试,只需导入该组件也会引发以下错误:
return import( /* webpackChunkName: "Modal" */"../pages/common/Modal.vue");
^^^^^^
SyntaxError: Unexpected token import
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
at Object.<anonymous> (srcVue/pages/landing/TileEditModal.vue.test.js:3:22)
Run Code Online (Sandbox Code Playgroud)
我试过这个解决方案,但它对我没用.
我正在使用jest-vue-preprocessor开玩笑:
"jest": {
"moduleFileExtensions": [
"js",
"vue"
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/jest-vue-preprocessor"
},
"clearMocks": …Run Code Online (Sandbox Code Playgroud) 我有一个组件:
import React from 'react';
import * as styles from './RedComponent.css';
class RedComponent extends React.Component {
render () {
return <div className={ styles.red }></div>;
}
}
Run Code Online (Sandbox Code Playgroud)
这是测试用例:
describe('Test suite', () => {
test('RedComponent tests', () => {
const wrapper = shallow(<RedComponent />);
});
Run Code Online (Sandbox Code Playgroud)
console.log(wrapper.debug());
给
<div className={[undefined]}></div>
Run Code Online (Sandbox Code Playgroud)
代替
<div className="RedComponent__red"></div>
Run Code Online (Sandbox Code Playgroud)
如果我控制我得到的导入样式
console.log(styles); // {default: {}}
Run Code Online (Sandbox Code Playgroud)
这只是在Jest测试用例中.当应用程序在浏览器中呈现时,样式未定义.
我的开玩笑配置:
{
"moduleFileExtensions": [
"js"
],
"moduleDirectories": [
"node_modules"
],
"moduleNameMapper": {
"\\.(css|less)$": "identity-obj-proxy"
},
"setupFiles": [
"./test-setup.js"
],
"collectCoverageFrom": [
"src/**/*.{js}",
"!**/node_modules/**"
], …Run Code Online (Sandbox Code Playgroud) 我有几个具有通用接口的类。我想一次编写一个Jest测试套件,并将其应用于所有类。理想情况下,不应将其混入一个测试模块中,相反,我希望将此套件导入到每个类的每个单独的测试模块中。
有人可以指出一个完成此类工作的项目或提供示例吗?谢谢。
我试图忽略testMatchJest模式中的特定文件夹。
我将测试放在一个__tests__文件夹中,并且希望能够将__config__其中所有文件都忽略的文件夹放进去。
/__tests__
/__config__
someConfig.jsx
/MyComponent.jsx
/MyComponent.jsx
Run Code Online (Sandbox Code Playgroud)
我在__tests__文件夹中的测试将从文件夹中导入文件,__config__因此我不想使用忽略它们transformIgnorePatterns。
但是,如果我不忽略该文件夹,Jest会尝试在该文件夹中运行并返回错误:
失败
src/components/__tests__/__config__/someConfig.jsx您的测试套件必须包含至少一个测试。
我尝试了几种不同的模式,但是找不到忽略__config__文件夹的方法
testMatch: [
"**/__tests__/!(__config__)/**/*.(js)?(x)", // Doesn't work
"**/__tests__/(**|!__config__)/*.(js)?(x)", // Doesn't work
"**/__tests__/(**|?!__config__)/*.(js)?(x)", // Doesn't work
"**/__tests__/{**,!__config__}/*.(js)?(x)", // Doesn't work
],
Run Code Online (Sandbox Code Playgroud)
知道如何忽略这样的子文件夹吗?
尝试使用api回调模拟其中一个功能,并得到如下错误 TypeError: specificMockImpl.apply is not a function
import { IEnvironmentMap, load } from 'dotenv-extended';
import { getTokensWithAuthCode, sdk } from '../src/connection-manager';
describe('getTokensWithAuthCode function Tests', () => {
jest.useFakeTimers();
let boxConfig: IEnvironmentMap;
beforeAll(() => {
boxConfig = load({
errorOnMissing: true,
});
});
it('should reject a promise if there is wrong auth code provided', async () => {
sdk.getTokensAuthorizationCodeGrant = jest.fn().mockImplementation(boxConfig.BOX_AUTH_CODE, null, cb => {
cb('Error', null);
});
try {
const tokens = await getTokensWithAuthCode();
} catch (error) {
expect(error).toBe('Error');
}
}); …Run Code Online (Sandbox Code Playgroud) 我正在使用JEST连接到spring-boot应用程序中的elasticsearch。当应用程序闲置一段时间(不向elasticsearch发送任何请求)时,JestClient会引发SocketTImeoutException。我正在使用Bean创建客户端:
@Bean
public JestClient client() throws Exception {
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(new HttpClientConfig
.Builder(esURL)
.multiThreaded(true)
.connTimeout(60000)
.readTimeout(60000)
.defaultMaxTotalConnectionPerRoute(10)
.maxTotalConnection(100).build());
return factory.getObject();
}
Run Code Online (Sandbox Code Playgroud)
我在这里想念什么吗?
在Jest中运行e2e测试之前,我需要从服务器获取身份验证令牌.
是否可以在全局范围内执行此操作并将其设置为每个测试的全局环境/上下文?
我尝试使用globalSetup配置选项:
const auth = require('./src/auth')
const ctx = require('./src/context')
module.exports = () => {
return new Promise(res => {
auth.getToken()
.then(token => {
ctx.init({token})
global.token = token
res()
})
})
}
Run Code Online (Sandbox Code Playgroud)
context.js
let _token
const init = ({token}) => {
_token = token
}
const getToken = () => {
return _token
}
module.exports = {
init,
getToken
}
Run Code Online (Sandbox Code Playgroud)
但两者都global.token没有ctx.getToken()返回undefined.
我需要使用帮助脚本并将令牌作为env var传递,然后将其设置为global.
"scripts": {
"test": "TOKEN=$(node src/get-token.js) jest" …Run Code Online (Sandbox Code Playgroud) 假设我有一个类如下:
class SomeClass {
constructor(a, b) {
this.a = a;
this.b = b;
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能通过Jest测试构造函数是否以正确的方式初始化?说... this.a = a和this.b = b,而不是相反?
我知道我可以执行,toBeCalledWith但这不会让我检查构造函数的逻辑.我也在考虑制作,mockImplementation但在这种情况下似乎没有意义,因为我将重写逻辑,或者我可能没有意识到创建模拟的所有细微差别
jest ×10
javascript ×6
java ×2
unit-testing ×2
babel ×1
css ×1
css-modules ×1
e2e-testing ×1
javabeans ×1
reactjs ×1
spring ×1
testing ×1
typescript ×1
vue.js ×1
webpack ×1