jest

Async setup of environment with Jest

倖福魔咒の 提交于 2019-12-12 10:57:53
问题 Before running e2e tests in Jest I need to get an authentication token from the server. Is it possible to do this globally one and set it somehow to the global environment / context for each test ? I tried it with globalSetup config option: 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() }) }) } context.js let _token const init = ({token})

How to test a stateless component

馋奶兔 提交于 2019-12-12 10:53:19
问题 I am trying to test below component but getting error, its a functional component with some data. The below component receive list of informations from parent component and renders, its work perfectly, but when writing test cases its failing using jest and enzyme import React from "react"; export const InfoToolTip = data => { const { informations = [] } = data.data; const listOfInfo = () => { return informations.map((info, index) => { const { name, id } = info; return [ <li> <a href={`someURL

How to get more than 10 thousand Documents at a time from Elasticsearch Using Jest client

淺唱寂寞╮ 提交于 2019-12-12 02:08:50
问题 ElasticSearch by-default gives 10 records, but we can set the size parameter and can get the more than 10 records but there is limit, we can set only 10000 as record size if we use Jest client for Elasticsearch, if its more than 10 thousand then throws Exception. please help me to get more than 10 thousand records at once in elasticsearch using jest client(java) Thanks in Advance 回答1: That limit is there for a reason — quoting from the documentation: The index.max_result_window which defaults

Jest not able to verify presence for a proeprty using toHaveProperty

时光毁灭记忆、已成空白 提交于 2019-12-11 15:07:47
问题 I am using Jest and enzyme, I have a react component, below its structure when performing .debug() . console.log src\shared\navigation\Navigations.test.js:20 <NavLink to="/" exact={true} activeStyle={{...}} activeClassName="active"> Weather </NavLink> I am using the following code to try to test if NavLink has a property to with value / . The property is not found (I believe when the component is mounted using shallow the object is decorated with other properties [code below]). I need to know

Enzyme test: TypeError: expect(…).find is not a function

半世苍凉 提交于 2019-12-11 11:54:29
问题 Why is .find not a function in the code context below? import React from 'react'; import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import { AuthorizedRoutesJest } from './AuthorizedRoutes'; // Components import { Main } from '../../components'; const wrapper = shallow(<AuthorizedRoutesJest />); describe('<AuthorizedRoutes /> component', () => { it('should render', () => { const tree = toJson(wrapper); expect(tree).toMatchSnapshot(); expect(wrapper).toHaveLength(1); });

How can I test an internal method inside a component in React?

浪子不回头ぞ 提交于 2019-12-11 11:54:20
问题 I am trying to test spy a method used inside a React component but I am failing. The component is the below : export class SiderMenu extends PureComponent { formatter(data, parentPath = '', parentAuthority) { return data.map((item) => { const result = { ...item, path: `${parentPath}${item.path}`, }; return result; }); } constructor(props) { super(props); this.menus = this.formatter(props.menuData); } render(....) } I am using enzyme and I want to test that the formatter method has been called

Delete ElasticSearch by Query with JEST

一笑奈何 提交于 2019-12-11 05:30:50
问题 I have some custom data(let's call Camera ) in my ElasticSearch, the data showed in Kibana is like And I tried to delete data by Query according to the accepted answer in this article ElasticSearch Delete by Query, my code is like String query = "{\"Name\":\"test Added into Es\"}"; DeleteByQuery delete = new DeleteByQuery.Builder(query).addIndex(this._IndexName).addType(this._TypeName).build(); JestResult deleteResult = this._JestClient.execute(delete); And the result is 404 Not Found . Its

fetch doesn't work in jest, and return TypeError: Network request failed

送分小仙女□ 提交于 2019-12-11 02:29:27
问题 I am trying to migrate from karma + PhantomJS to Jest + jsDom, but I got a problem. all fetch in UT failed in Jest. I am trying to figure out the reason. So I just write a simple UT like this import fetch from 'isomorphic-fetch'; import $ from 'jquery'; describe('test', () => { it('should fetch success....', (done) => { return fetch('http://www.ebay.com/', { method: 'get' }) .then((res) => { console.log(res); done(); }) .catch(err => console.log(err)); }) it('should get success....', (done) =

Write a jest test to my first component

谁都会走 提交于 2019-12-11 00:24:12
问题 I just finished writing my first Reactjs component and I am ready to write some tests (I used material-ui 's Table and Toggle ). I read about jest and enzyme but I feel that I am still missing something. My component looks like this (simplified): export default class MyComponent extends Component { constructor() { super() this.state = { data: [] } // bind methods to this } componentDidMount() { this.initializeData() } initializeData() { // fetch data from server and setStates } foo() { //

Elasticsearch - get source field data with java api

﹥>﹥吖頭↗ 提交于 2019-12-10 13:45:13
问题 I'm using elastic search with jest (as java client). I need some fields that is in nested document and since cannot get nested fields as pair, I need '_source' to get them. Here is previous question to get them in ES query[ Link ], and It works well. BUT cannot convert its query as jest code. Below is my try. SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query( query ) .fields( // need _source but no method. "oid", "_source.events.activityoid", "_source.events.worktime")