Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'enzyme-adapter-react-15' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
import React from 'react'
import Adapter from 'enzyme-adapter-react-15'
import { configure, shallow, mount } from 'enzyme'
import { Crowdsales } from '../../../src/components/Crowdsales'
import { CrowdsalesList } from '../../../src/components/Crowdsales/CrowdsalesList'
import { crowdsaleStore, contractStore, web3Store, generalStore } from '../../../src/stores'
import { Provider } from 'mobx-react'
import renderer from 'react-test-renderer'
configure({ adapter: new Adapter() })
describe('Crowdsales', () => {
const stores = { crowdsaleStore, web3Store, generalStore, contractStore }
it('should render screen ', () => {
// Given
const tree = renderer.create(
)
// When
const treeJson = tree.toJSON()
// Then
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';
Enzyme.configure({ adapter: new Adapter() });
// Storage Mock
// TODO: Some places in our code (e.g. translations) has a hardcoded dependency
// to the local storage. Fixing it and we can remove this global mock.
function storageMock() {
let storage = {};
return {
setItem: function(key, value) {
storage[key] = value || '';
},
getItem: function(key) {
return key in storage ? storage[key] : null;
},
import { configure } from 'enzyme';
import { JSDOM } from 'jsdom';
// enzyme requires special adapters now that are in different modules
// as opposed to different imports, so we need to configure it based on
// which React version we're testing
if (process.env.REACT_VERSION === '^15.4.0') {
const Adapter = require('enzyme-adapter-react-15.4');
configure({ adapter: new Adapter() });
} else if (process.env.REACT_VERSION === '<15.4.0 >15.0.0') {
const Adapter = require('enzyme-adapter-react-15');
configure({ adapter: new Adapter() });
} else {
const Adapter = require('enzyme-adapter-react-16');
configure({ adapter: new Adapter() });
}
module.exports = function(root) {
root = root ? root : global;
root.expect = root.chai.expect;
const dom = new JSDOM('');
root.window = dom.window;
root.document = dom.window.document;
beforeEach(() => {
// Using these globally-available Sinon features is preferrable, as they're
import React from 'react';
import { expect } from 'chai';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';
import { mount } from 'enzyme';
import sinon from 'sinon';
import FormControl from 'react-bootstrap/lib/FormControl';
import TopForm from './TopForm.react';
import { I18nManager } from '@opuscapita/i18n';
Enzyme.configure({ adapter: new Adapter() });
describe('', () => {
it('renders top form', () => {
const props = {
name: 'Invoice workflow',
onNameChange: sinon.spy()
};
const wrapper = mount(, { context: { i18n: new I18nManager() } });
expect(wrapper).to.exist; // eslint-disable-line no-unused-expressions
expect(wrapper.contains(FormControl)).to.be.true; // eslint-disable-line no-unused-expressions
expect(wrapper.find(FormControl).prop('value')).to.equal(props.name);
expect(wrapper.find(FormControl).prop('onChange')).to.equal(props.onNameChange);
});
});
import React from 'react';
import {configure as configureEnzyme, mount} from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';
configureEnzyme({adapter: new Adapter()});
import {matcherResult} from './common';
import jestDiff from 'jest-diff';
const root = document.createElement('div');
document.body.appendChild(root);
let lastRendered;
const testRender = element => {
lastRendered = mount(element, {attachTo: root});
// eslint-disable-next-line no-console
lastRendered.print = () => console.log(lastRendered.debug());
return lastRendered;
};
const testReset = () => {
lastRendered && lastRendered.unmount();
// This is a configuration file for Jest
import './sprockets-shims.js';
import '../legacy.js';
// Enzyme support
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-15.4';
Enzyme.configure({ adapter: new Adapter() });
// These are for MountTimer and measurePageLoad.
// See https://gist.github.com/ShirtlessKirk/eb41720a797411defae6
import './performance-timing-api.js';
import {performance} from 'perf_hooks';
global.performance = performance;
// https://github.com/jefflau/jest-fetch-mock
global.fetch = require('jest-fetch-mock'); // eslint-disable-line no-undef
// Make console.warn and error fail tests
console.error = jest.fn(error => { throw new Error(error); }); //eslint-disable-line no-console
console.warn = jest.fn(warn => { throw new Error(warn); }); //eslint-disable-line no-console
// Make test fail if code is reporting errors to Rollbar
window.Rollbar = {
/*
* Bounce Component Test Suite
*
* Copyright © Roman Nosov 2016
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
import Bounce from '../../Bounce';
import React from 'react';
import { shallow } from 'enzyme';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';
configure({ adapter: new Adapter() });
describe('Bounce', () => {
it('renders a initial view', () => {
const content = shallow(
<div>Test test</div>
);
expect(content.html()).toMatchSnapshot();
});
});
import { MemoryRouter } from 'react-router'
import { Manage } from '../../../src/components/Manage/index'
import {
crowdsaleStore,
web3Store,
tierStore,
contractStore,
reservedTokenStore,
stepTwoValidationStore,
generalStore,
tokenStore,
gasPriceStore,
deploymentStore
} from '../../../src/stores'
configure({ adapter: new Adapter() })
describe('Manage index', () => {
const stores = {
crowdsaleStore,
web3Store,
tierStore,
contractStore,
reservedTokenStore,
stepTwoValidationStore,
generalStore,
tokenStore,
gasPriceStore,
deploymentStore
}
it(`should render Manage`, () => {
import React from 'react'
import { Error } from '../../../src/components/Common/Errors'
import { Form } from 'react-final-form'
import Adapter from 'enzyme-adapter-react-15'
import { configure, mount, shallow } from 'enzyme'
import renderer from 'react-test-renderer'
import { FORM_ERROR } from 'final-form'
import {validateTierMinCap} from "../../../src/utils/validations";
configure({ adapter: new Adapter() })
describe('Error ', () => {
const errorStyle = {
color: 'blue',
fontWeight: 'bold',
fontSize: '24px',
width: '50%',
height: '10px'
}
it(`should render Error component`, () => {
const getErrors = () =>{
return FORM_ERROR
}