011: Testing!
describe('GET /messages', () => {
it('should require a token', (done) => {
// do something
});
});const greet = require('../Greeting');
describe('Greeting', () => {
it('has correct form', () => {
const result = greet('Liam');
const expected = 'Hello, Liam!';
// assertions
});
});
Simple JS module
API endpoint
const greet = require('../Greeting');
describe('Greeting', () => {
it('has correct form', () => {
const result = greet('Liam');
const expected = 'Hello, Liam!';
expect(result).toEqual(expected);
});
});
const express = require('express');
const request = require('supertest');
const app = express();
const api = require('../api')
// make api available
app.use(api);
describe('/person', () => {
it('should return a JSON person', () => {
// send a request
return request(app)
.get('/person')
const express = require('express');
const request = require('supertest');
const app = express();
const api = require('../api')
// make api available
app.use(api);
describe('/person', () => {
it('should return a JSON person', () => {
// send a request
return request(app)
.get('/person')
// verify response
.expect(200)
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(res => {
const person = res.body;
expect(person.name).toEqual('Liam');
expect(person.age).toEqual('22');
});
});
});
const express = require('express');
const request = require('supertest');
const app = express();
const api = require('../api')
// make api available
app.use(api);
describe('/person', () => {
it('should return a JSON person', () => {
// send a request
return request(app)
.get('/person')
// verify response
.expect(200)
.expect('Content-Type', 'application/json; charset=utf-8')
.expect(res => {
const person = res.body;
expect(person.name).toEqual('Liam');
expect(person.age).toEqual('22');
});
});
});
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
// package.json
"test": "react-scripts test --env=jsdom",
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import EmailInput from '../../../src/web/components/EmailInput.jsx';
describe('EmailInput', () => {
it('is a div that contains a label', () => {
// ...
});
});it('renders correctly', () => {
const tree = renderer.create(
<Link page="http://www.instagram.com">Instagram</Link>
).toJSON();
expect(tree).toMatchSnapshot();
});