Skip to content

Instantly share code, notes, and snippets.

//I created an object called "testData", filled with a bunch of save/enemy/card examples.
describe("Express Routes", () => {
describe("/api/cards/", () => {
beforeEach(() => Card.sync({ force: true }));
beforeEach(() => Card.bulkCreate(testData.cardData, { returning: true }));
it("GET /api/cards - returns all cards", async () => {
const res = await request(app) // Here's the power of Supertest! It can make GET/POST/PUT/DELETE requests!
.get("/api/cards")
@LadyLeTired
LadyLeTired / tests.spec.js
Created January 21, 2019 20:51
Card Model specs
describe("Card Model", () => {
// Mocha handles asynchronous actions, like Card.sync below. So, no need for async/await or .then! Woop!
before("Synchronize the model", () => Card.sync({ force: true }));
// Truncating data in a table is a bit less cumbersome than dropping/recreating it.
beforeEach("Truncate data", () => Card.truncate());
describe("Schema", () => {
it('requires a "name" string', async () => {
await expect(Card.create()).to.be.rejected; // No data? No card!
const chai = require("chai");
const { expect } = require("chai");
const db = require("./models");
const chaiAsPromised = require("chai-as-promised");
//chai-as-promised allows us to make assertions about lines of code which return Promises, as opposed to immediate return values!
chai.use(chaiAsPromised);
const Card = db.Card;
const Enemy = db.Enemy;
{
"scripts": {
"test:server": "mocha ./server/db/tests.spec.js --exit",
"test:client": "jest ./app/components/__tests__",
"creature-feature-quest-test": "npm run test:server & npm run test:client"
},
}