Add basic test suite using jest. Initiate with 'npm test'

This commit is contained in:
Elliot DeNolf
2018-04-21 00:09:07 -06:00
parent 5867715598
commit 9e43751b93
6 changed files with 5662 additions and 6 deletions

View File

@@ -34,4 +34,4 @@ app.get('/', (req, res) => res.render('index',
title: 'Index'
}));
app.listen(3000, () => console.log('Example app listening on http://localhost:3000'))
app.listen(3000, () => console.log('Example app listening on http://localhost:3000'));

5609
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node ./node_modules/jest/bin/jest.js"
},
"author": "",
"license": "ISC",
@@ -15,6 +15,7 @@
"pug": "^2.0.3"
},
"devDependencies": {
"eslint": "^4.19.1"
"eslint": "^4.19.1",
"jest": "^22.4.3"
}
}

View File

@@ -4,7 +4,8 @@
"browser": true,
"commonjs": true,
"node": true,
"es6": true
"es6": true,
"jest": true
},
"parserOptions": {
"sourceType": "module",

View File

@@ -4,7 +4,7 @@ const Collection = require('./Collection');
class Payload {
constructor(options) {
this.app = options.express;
this.express = options.express;
this.mongoose = options.mongoose;
this.baseURL = options.baseURL;
@@ -12,7 +12,7 @@ class Payload {
this.collections = {};
this.app.get(`/payload/admin`, function (req, res) {
this.express.get(`/payload/admin`, function (req, res) {
res.render('admin',
{
title: 'Payload Admin'

View File

@@ -0,0 +1,45 @@
const express = require('express');
const app = express();
const mongoose = require('mongoose');
const Payload = require('../');
describe('Basic Payload Tests', () => {
test('Instantiate Payload', () => {
const payload = initBasicPayload();
expect(payload).toBeDefined();
});
test('Create new collection', () => {
const payload = initBasicPayload();
let collection = payload.newCollection('key');
expect(collection).toBeDefined();
});
test('Retrieve collection', () => {
const payload = initBasicPayload();
let collection = payload.newCollection('key');
collection.register();
let retrieved = payload.getCollection('key');
expect(retrieved).toBeDefined();
});
});
describe('Collection tests', () => {
test('Add fields to collection', () => {
const payload = initBasicPayload();
let collection = payload.newCollection('key');
collection.add({
test: { testProp: 'firstProp'}
});
expect(collection.fields.test.testProp).toBe('firstProp');
});
});
function initBasicPayload() {
return new Payload({
express: app,
mongoose,
baseURL: 'base123'
});
}