Testing


John Alexis Guerra Gómez


Slides:http://johnguerra.co/lectures/webDevelopment_fall2019/11_Testing/

Class page:http://johnguerra.co/classes/webDevelopment_fall2019/

Readings discussion

  • questions?

Testing

Types of Testing

  • Unit test
  • Integration test
  • Acceptance test (end to end test)
  • Load test

Testing React

We need:

Install dependencies

meteor npm install --save-dev enzyme
meteor npm install --save-dev react-test-renderer@15
meteor npm install --save-dev enzyme enzyme-adapter-react-15

Add test files

Create a ./both/setup.tests.js that setups the adapter for enzyme

Then create a ./imports/ui/Controls.tests.js that test the Controls React component

./both/setup.tests.js

// setup file
import { configure } from "enzyme";
import Adapter from "enzyme-adapter-react-15";

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

./imports/ui/Controls.tests.js

import React from "react";
import { shallow } from "enzyme";
import { chai } from "meteor/practicalmeteor:chai";
import Controls from "./Controls.jsx";


describe("Controls", () => {
  it("should render", () => {

    const controls = shallow(<Controls onMove={this.onMove}></Controls>);
    chai.assert(controls.hasClass("Controls"));
    chai.assert(controls.find("button").length, 4);
  });
});