tylercollier / redux-form-test

Shows how to do unit tests and integration tests with Redux-Form
219 stars 26 forks source link

Uncaught ReferenceError: chai is not defined #2

Closed SRCres closed 8 years ago

SRCres commented 8 years ago

I'm trying to implement the way you tests redux-form but there is something wrong when I import sinon-chai module. It seems chai is not imported before sinon-chai use it and I don't figure out how fix it. I know this isn't a redux-form-test bug, but may be you can help me anyway.

Test file

import SignInFormComponent from 'js/components/SignInFormComponent';
import React from 'react';

import chai, { expect } from 'chai';
import sinonChai from 'sinon-chai';
import { shallow } from 'enzyme';
import chaiEnzyme from 'chai-enzyme';
import sinon from 'sinon';

chai.use(sinonChai);
chai.use(chaiEnzyme());

sinon-chai file

// Module systems magic dance.

    /* istanbul ignore else */
    if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
        // NodeJS
        module.exports = sinonChai;
    } else if (typeof define === "function" && define.amd) {
        // AMD
        define(function () {
            return sinonChai;
        });
    } else {
        // Other environment (usually <script> tag): plug in to global chai instance directly.
        chai.use(sinonChai);
    }

Error occurs in chai.use(sinonChai);.

I use Webpack for modules.

tylercollier commented 8 years ago

I'm using webpack too.

What is your actual error message? Is it a build time error from webpack, or runtime with the test runner?

I'm not sure if this will help you, but I just created a branch, 2-sinon-chai-not-needed, to show that sinon-chai is not NEEDED for the code that I've written. If you want it, that's fine; I mention it in case you might be able to just remove it from your project to save yourself the headache that's happening.

SRCres commented 8 years ago

It's a runtime error and shows in the console. I'll remove sinon-chai and save myself the suffering. Thanks for reply!

tylercollier commented 8 years ago

I've merged branch 2-sinon-chai-not-needed to master and updated the README to remove its mention.