-
Notifications
You must be signed in to change notification settings - Fork 0
Implement frontend testing #22
Comments
As a proof of concept, make a list of possible tests using Jest then apply appropriate tests to the ItemViewAppBar component. |
The begin with, start by writing tests for the ItemViewAppBar component. The tests should include but may not be limited to:
Its not immediately clear how to test for a theme being passed. Perhaps the component should be edited to assume a sane default (the default MUI theme) when one isn't present and the Some useful resources: |
@celfreic is working through ReactJS intro material and will resume work on this after that. |
Helpful Resources on getting started:
|
Intro to React Testing (cont.): For an example: Suppose you have a form with basic html structure inside a rendered react App <div>
<h1>TODOS</h1>
<ul>
{items.map((item) => (
<li key={item.id}>{item.text}</li>
))}
</ul>
<form onSubmit={handleSubmit}>
<label htmlFor="new-todo">What needs to be done?</label>
<br />
<input id="new-todo" value={text} onChange={handleChange} />
<button>Add #{items.length + 1}</button>
</form>
</div> You can implement a test via raw javascript and the react dom that verifies the text via query selectors from the document and then pulling the text content: import React from "react";
import ReactDOM from "react-dom";
import { App } from "./App";
test("it works", () => {
const root = document.createElement("div");
ReactDOM.render(<App />, root);
expect(root.querySelector("h1").textContent).toBe("TODOS");
expect(root.querySelector("label").textContent).toBe(
"What needs to be done?"
);
expect(root.querySelector("button").textContent).toBe("Add todo");
}); Abstracting this a layer away via the dom testing library allows for more elegant code and queried selectors that are labels will verify properties automatically like having an htmlFor tag: import React from "react";
import ReactDOM from "react-dom";
import { within } from "@testing-library/dom";
import { App } from "./App";
test("it works", () => {
const root = document.createElement("div");
ReactDOM.render(<App />, root);
const { getByText, getByLabelText } = within(root);
// expect(getByText("TODOS")).not.toBeNull();
// expect(getByLabelText("What needs to be done?")).not.toBeNull();
// expect(getByText("Add #1")).not.toBeNull();
// Above code can be shortend to
getByText("TODOS");
getByLabelText("What needs to be done?");
getByText("Add #1");
}); Furthermore, adding the react testing library will make rendering abstracted away and reduce our code as it encapsulates the dom testing within: import React from "react";
import { App } from "./App";
import { render } from "@testing-library/react";
test("it works", () => {
const { getByText, getByLabelText } = render(<App />);
getByText("TODOS");
getByLabelText("What needs to be done?");
getByText("Add #1");
}); The tutorial also provides a useful sandbox example for simulating user clicks and interaction here |
Before adding functionality to the UI (but while addressing current bugfixes and improvements), testing needs to be prioritized and standardized. |
After watching a talk about Test Driven Development at Python Web Conf, I feel the creation and upkeep of tests doesn't provide near enough benefit to spend time on without dedicated testing staff. Will keep this issue open as a feature request without milestone. |
Not within current scope. Closing. |
Currently there is no testing implemented for the frontend which could allow for a change to inadvertently break things until discovered manually. Tests should be written to confirm that one change doesn't break other functionality.
Jest seems to be the testing framework included with create-react-app.
The text was updated successfully, but these errors were encountered: