Skip to content

Instantly share code, notes, and snippets.

View gonzalolarrosa's full-sized avatar

gonzalolarrosa

View GitHub Profile
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.getRegistrations().then(registrations => {
for(let registration of registrations) {
registration.unregister().then(bool => {console.log('unregister: ', bool);});
}
window.location.reload();
});
});
}
import { SUPERHEROES } from '../Constants';
describe("Constants", () => {
it("SUPERHEROES should match snapshot", () => expect(SUPERHEROES).toMatchSnapshot());
});
export const SUPERHEROES = [
‘Batman’,
‘Superman’,
‘Deadpool’,
‘Wolverine’
];
import Header from '../Header';
const DATA = {
title: ‘Avengers’,
subtitle: ‘Infinity War’
};
const wrapper = shallow(<Header data={DATA} />);
//we omit the unit tests for props
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 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 { 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 ChildComponent from '../ChildComponent';
const onSubmitSpy = jest.fn();
const onSubmit = onSubmitSpy;
const wrapper = shallow(<ChildComponent onSubmit={onSubmitSpy} />);
let container, containerButton;
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, { 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
};