jest

Jest fails to transpile import from npm linked module

你说的曾经没有我的故事 提交于 2019-12-05 16:53:23
I have a project with multiple modules (using Lerna ) and I want to use Jest to run tests. However, when I test code that uses a shared module (npm linked module via Lerna) it seems that Babel is not correctly applied and I get the following error: SyntaxError: Unexpected token import The structure of my project is like this: - my-project |- shared |- native |- web web and native require the shared module. When I go into the shared directory and run the local tests in Jest everything works fine. If I run Jest tests in the web directory the above error occurs as soon as I include something from

How to write jest test cases for navigation in react

此生再无相见时 提交于 2019-12-05 13:49:54
I am new to Jest test cases writing, Trying to write the test case for checking navigation in an react application. Currently I have written test case which works like below: I have Login page which is having register link on it, which redirects user to the Register page. So what I am checking is 1. Loading the login page 2. Triggered Register link click event 3. So user moved to the Register page but I am not able to check if the Register page is loaded or not? Is there any way to check the snapshot of the "Register" page and link in URL. I have used jest, enzyme and react-test-render as

React Native - mocking FormData in unit tests

女生的网名这么多〃 提交于 2019-12-05 05:27:36
I'm having issues testing my thunks, as many of my API calls are using FormData, and I can't seem to figure out how to mock this in tests. I'm using Jest. My setup file looks like this: import 'isomorphic-fetch'; // Mocking the global.fetch included in React Native global.fetch = jest.fn(); // Helper to mock a success response (only once) fetch.mockResponseSuccess = body => { fetch.mockImplementationOnce(() => Promise.resolve({ json: () => Promise.resolve(JSON.parse(body)) }) ); }; // Helper to mock a failure response (only once) fetch.mockResponseFailure = error => { fetch

Serverless 实战 —— Funcraft + OSS + ROS 进行 CI/CD

元气小坏坏 提交于 2019-12-04 20:02:50
前言 首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute) :函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。函数计算更多信息 参考 。 Funcraft :Funcraft 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API 网关、日志服务等资源。它通过一个资源配置文件(template.yml),协助您进行开发、构建、部署操作。Fun 的更多文档 参考 。 OSS : 对象存储。海量、安全、低成本、高可靠的云存储服务,提供99.9999999999%的数据可靠性。使用RESTful API 可以在互联网任何位置存储和访问,容量和处理能力弹性扩展,多种存储类型供选择全面优化存储成本。 ROS :资源编排(ROS)是一种简单易用的云计算资源管理和自动化运维服务。用户通过模板描述多个云计算资源的依赖关系、配置等,并自动完成所有资源的创建和配置,以达到自动化部署、运维等目的。编排模板同时也是一种标准化的资源和应用交付方式,并且可以随时编辑修改,使基础设施即代码(Infrastructure as Code)成为可能。 CI/CD : CI/CD

how to get type names of elastic search index in internal java api or jest api

*爱你&永不变心* 提交于 2019-12-04 18:55:12
问题 I have a index with the name of demo and It contains different types. I'm using elastic search java internal api and rest api jest both of them in my app. Basicly I want to make this request curl -XGET 'http:localhost:9200/demo/_mapping' Is there any way to do that especially in jest api? There is no documentation to get mapping for rest client api. What is your suggestion ? 回答1: This should work, but it's really ugly: GetMappingsResponse res = client.admin().indices().getMappings(new

OR and AND Operators in Elasticsearch query

亡梦爱人 提交于 2019-12-03 23:56:49
I have few json document with the following format :- _source: { userId: "A1A1", customerId: "C1", component: "comp_1", timestamp: 1408986553, } I want to query the document based on the following :- (( userId == currentUserId) OR ( customerId== currentCustomerId) OR (currentRole ==ADMIN) ) AND component= currentComponent) I tried using the SearchSourceBuilder and QueryBuilders.matchQuery, but I wasnt able to put multiple sub queries with AND and OR operators. SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.query(QueryBuilders.matchQuery("userId",userId

Java HTTP Client for ElasticSearch

南笙酒味 提交于 2019-12-03 08:27:19
问题 I'm trying to connect from Java to ElasticSearch but I can only connect over HTTP. I can't use the TransportClient . Is there a Java client wrapper around the ElasticSearch REST APIs? If so, how do I use it? 回答1: Hi There is a brand new project just matching your needs. It Java based Rest API for Elasticsearch Check it out! its name JEST 回答2: A new "official" REST-based java client will be available starting with v5.0.0-alpha4. 回答3: We just open sourced Flummi, a Java HTTP/REST client for

Scoping in Jest when mocking functions

末鹿安然 提交于 2019-12-02 02:41:48
问题 I have a test where I'm trying to mock a component in two different situations. When I use jest.fn . It almost looks like the first test is just taking the value from the second. describe('tests', () => { let sampleArray = new Array() Array.prototype.test = function() { return this.innerArray() } describe('empty', () => { sampleArray.innerArray = jest.fn(() => []) it('testArray is empty', () => { expect(sampleArray.test().length).toEqual(0) }) }) describe('not empty', () => { sampleArray

Manual mock not working in with Jest

余生长醉 提交于 2019-12-02 00:15:31
问题 Can somebody help me with manual mocking in Jest, please? :) I try to have Jest use the mock instead of the actual module. my test: // __tests__/mockTest.js import ModuleA from "../src/ModuleA" describe("ModuleA", () => { beforeEach(() => { jest.mock("../src/ModuleA") }) it("should return the mock name", () => { const name = ModuleA.getModuleName() expect(name).toBe("mockModuleA") }) }) my code: // src/ModuleA.js export default { getModuleName: () => "moduleA" } // src/__mocks__/ModuleA.js

How do I test `image.onload` using jest in the context of redux actions (or other callbacks assigned in the action)

谁说胖子不能爱 提交于 2019-12-01 19:21:33
My problem was that I am trying to make a unit test for a function but can't figure out how to test a part of it. This is a react / redux action that does the following: 1) retrieves json data with an image url 2) loads the image into an Image instance and dispatches its size to the reducer (asynchronously when image is loaded using Image.onload) 3) dispatches that the fetch was completed to the reducer The image onload happens asynchronously, so when I try to unit test it it wouldn't be called. Moreover, I can't just mock things out because the image instance is created within the function...