This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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" | |
| }, | |
| } |