Code Monkey home page Code Monkey logo

enzyme-example-mocha's Introduction

enzyme-example-mocha

Example project with React + Enzyme + Mocha

enzyme-example-mocha's People

Contributors

lelandrichardson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

enzyme-example-mocha's Issues

mocha and webpack - Cannot find module 'home.scss'

I use this procedure to make test for my react - webpack app. When I execute the test I got this error.

My component is like this

import React from 'react'
import {Link} from 'react-router'
import 'home.scss'
import Footer from 'Footer'
import Nav from 'Nav'
import DocumentTitle from 'react-document-title'

export default class Home extends React.Component{
    render(){
        return(
            <div class="home">

            </div>
        )
    }
}

and mocha .setup.js is exactly like yours

require('babel-register')();

var jsdom = require('jsdom').jsdom;

var exposedProperties = ['window', 'navigator', 'document'];

global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
  if (typeof global[property] === 'undefined') {
    exposedProperties.push(property);
    global[property] = document.defaultView[property];
  }
});

global.navigator = {
  userAgent: 'node.js'
};

documentRef = document;

my home-test.js

import React from 'react';
import { expect } from 'chai';
import { shallow, mount, render } from 'enzyme';
import Home from '../component/home/home';

describe("home page", function() {
    it("contains spec with an expectation", function() {
        expect(shallow(<Home />).contains(<div className="home" />)).to.equal(true);
    });
});

what's up with the setup?

Hi, just curious about the setup code. Any chance enzyme would be able to abstract that away.. seems redundant.

TypeError: Cannot read property 'equal' of undefined

Hi,

That error occurs when I run these tests (occurs as well when I use shallow):

it("length is = 1", function() {
    expect(render(<Component />).find('.body').length).to.equal(1);
});

it("It has a footer", function() {
    const wrapper = shallow(<Component />);
    expect(wrapper.find('img')).to.have.length(1);
});

.setup.js file is the same and I have all of the dependencies installed.

Any tips to get this working?

Thanks.

Scoping issue with react component when using enzyme

Hi,

I have added a global object like localStorage in component render method and trying to test it with shallow rendered using enzyme. I am getting the below error, when i try to test using 'npm test'.

ReferenceError: localStorage is not defined

render() {
localStorage.setItem("name", "Smith");//can be used later
return (


);
}

If I remove localStorage from the code then all tests are good. Any idea how to get rid of it??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.