Sha256: b18e2878cc8c2c7dcecf310e2a1acfd06ffe86dd5c54bf12a3c5f08170d7362a

Contents?: true

Size: 1.65 KB

Versions: 21

Compression:

Stored size: 1.65 KB

Contents

import React from 'react';
import ReactDOM from 'react-dom';
import { configure, shallow } from 'enzyme';
import { expect } from 'chai';
import { spy, stub, useFakeTimers } from 'sinon'
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });

import App from '../src/App';
import Button from '../src/components/Button';

describe('<Button />', () => {
  var buttonWrapper

  //tests specific method within a class
  it('handles click correctly', () => {
    
    //set spy on a particular component's class method
    spy(Button.prototype, "handleClick")

    //example shallow mount of a component
    buttonWrapper = shallow(<Button />);

    //should console log when handleClick fires
    const fakeEvent = {target: {innerHTML: "test"}}

    //calls method on Button
    buttonWrapper.instance().handleClick(fakeEvent)

    //spy confirms the method was called
    expect(Button.prototype.handleClick.calledOnce, "handleClick was not called").to.equal(true)

    //prevents hanging tests
    buttonWrapper.unmount()
  });
})

describe('<App />', () => {
  var appWrapper

  //test if a component is mounting correctly
  it('mounts correctly', () => {
    appWrapper = shallow(<App />);

    expect(appWrapper, "App did not mount").to.exist

    appWrapper.unmount()
  });

  //test if required content is present in rendered HTML
  it('contains a Greeting and an Example component', () => {

    appWrapper = shallow(<App />);

    // check for html content directly
    expect(appWrapper.html()).to.include('<div class="Greeting">Hello!</div>')
    expect(appWrapper.html()).to.include('<strong>Example!</strong>')

    appWrapper.unmount()

  })

});

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
learn_create-0.0.22 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.20 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.19 lib/templates/react-lab-template/test/index.test.js
learn_duplicate-0.0.15 lib/templates/react-lab-template/test/index.test.js
learn_duplicate-0.0.14 lib/templates/react-lab-template/test/index.test.js
learn_duplicate-0.0.13 lib/templates/react-lab-template/test/index.test.js
learn_duplicate-0.0.12 lib/templates/react-lab-template/test/index.test.js
learn_duplicate-0.0.8 lib/templates/react-lab-template/test/index.test.js
learn_duplicate-0.0.5 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.18 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.17 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.15 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.14 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.13 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.11 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.10 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.9 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.8 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.7 lib/templates/react-lab-template/test/index.test.js
learn_create-0.0.6 lib/templates/react-lab-template/test/index.test.js