Add basic test suite using jest. Initiate with 'npm test'
This commit is contained in:
2
index.js
2
index.js
@@ -34,4 +34,4 @@ app.get('/', (req, res) => res.render('index',
|
|||||||
title: '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
5609
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "node ./node_modules/jest/bin/jest.js"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
"pug": "^2.0.3"
|
"pug": "^2.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^4.19.1"
|
"eslint": "^4.19.1",
|
||||||
|
"jest": "^22.4.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
"browser": true,
|
"browser": true,
|
||||||
"commonjs": true,
|
"commonjs": true,
|
||||||
"node": true,
|
"node": true,
|
||||||
"es6": true
|
"es6": true,
|
||||||
|
"jest": true
|
||||||
},
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"sourceType": "module",
|
"sourceType": "module",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ const Collection = require('./Collection');
|
|||||||
class Payload {
|
class Payload {
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.app = options.express;
|
this.express = options.express;
|
||||||
this.mongoose = options.mongoose;
|
this.mongoose = options.mongoose;
|
||||||
this.baseURL = options.baseURL;
|
this.baseURL = options.baseURL;
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ class Payload {
|
|||||||
|
|
||||||
this.collections = {};
|
this.collections = {};
|
||||||
|
|
||||||
this.app.get(`/payload/admin`, function (req, res) {
|
this.express.get(`/payload/admin`, function (req, res) {
|
||||||
res.render('admin',
|
res.render('admin',
|
||||||
{
|
{
|
||||||
title: 'Payload Admin'
|
title: 'Payload Admin'
|
||||||
|
|||||||
45
payload/tests/payload.test.js
Normal file
45
payload/tests/payload.test.js
Normal 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'
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user