Skip to content

Instantly share code, notes, and snippets.

View gonzalolarrosa's full-sized avatar

gonzalolarrosa

View GitHub Profile
import { getUserData } from '../Service';
const USER_ID = 1;
const USER_INFO = {
name: ‘Bruce Wayne’,
age: 32,
gender: ‘male’,
mail: ‘batman@dccomics.com’
}
import React, { Component } from 'react';
import './main-component.css';
import ChildComponent from './ChildComponent';
export default class MainComponent extends Component {
constructor (props) {
super(props);
this.label = “I’m your father”;
};
import React, { Component } from 'react';
import { string, func } from 'prop-types';
import './child-component.css';
export default class ChildComponent extends Component {
static propTypes = {
label: string,
onSubmit: func.isRequired
};
import React from 'react';
import { shallow } from 'enzyme';
import MainComponent from '../MainComponent';
jest.mock('../ChildComponent'); //ChildComponent is now a mock constructor
const wrapper = shallow(<MainComponent />);
let container, containerProp, childContainer, childContainerProps;
describe("MainComponent", () => {
import React from 'react';
import { shallow } from 'enzyme';
import ChildComponent from '../ChildComponent';
const onSubmitSpy = jest.fn();
const onSubmit = onSubmitSpy;
const wrapper = shallow(<ChildComponent onSubmit={onSubmitSpy} />);
let container, containerButton;
import React, { Component } from 'react';
import { string } from 'prop-types';
import './my-first-component.css';
export default class MyFirstComponent extends Component {
static propTypes = {
title: string
};
static defaultProps = {
import React from 'react';
import { shallow } from 'enzyme';
import MyFirstComponent from '../MyFirstComponent';
const wrapper = shallow(<MyFirstComponent />);
let container, containerProp;
describe("MyFirstComponent - No props", () => {
it("should have state set properly", () => {
expect(wrapper.state().buttonEnable).toEqual(true);
import React, { Component } from 'react';
import { object } from 'prop-types';
import './header.css';
export default class Header extends Component {
static propTypes = {
data: object
};
static defaultProps = {
import Header from '../Header';
const DATA = {
title: ‘Avengers’,
subtitle: ‘Infinity War’
};
const wrapper = shallow(<Header data={DATA} />);
//we omit the unit tests for props
export const SUPERHEROES = [
‘Batman’,
‘Superman’,
‘Deadpool’,
‘Wolverine’
];