Blueprint
  • Blueprint Developer Guide
  • Quick Start
    • Getting Started
    • My First Application
      • Creating Your Application
      • Controllers
      • Routers & Routes
      • Services
      • Resources & Resource Controllers
      • Validating & Sanitizing Input
      • Unit Testing Your Application
      • Policies
  • Developer Guide
    • The Object Model
      • Introduction
      • Classes and Instances
      • Computed Properties
      • Aggregated Properties
      • Mixins
    • Routers and Controllers
      • Introduction
      • Routers
      • Controllers
      • Resources
    • Models
    • The Server
    • Policy Framework
    • Services
    • Messaging Framework
    • Configuration Management
    • Application and Resources
      • Lookup Operation
      • Views
      • Assets
    • Blueprint Modules
    • Blueprint Cluster
      • What is a Blueprint Cluster?
      • Running a Blueprint Cluster
      • Technical Details
    • Testing Framework
    • Command-line Interface (Coming Soon)
Powered by GitBook
On this page
  1. Quick Start
  2. My First Application

Unit Testing Your Application

PreviousValidating & Sanitizing InputNextPolicies

Last updated 3 years ago

In the previous lessons, we learned how to use to simplify the controllers implementation. Now, we need to test our implementation so we can ensure it is handling requests correctly.

Blueprint uses and to facilitate unit testing. The benefit to Blueprint approach is it allows you to run unit tests without needing a front-end, such as Postman, to exercise the Blueprint application. You can also use to implement the test oracle for each unit test.

Using our current example, here is a simple unit test to check the GET /api/rentals.

// tests/unit-tests/app/routers/rental.js

const { request } = require ('@onehilltech/blueprint-testing');
const { expect } = require ('chai');

describe ('app | routers | rental', function () {
  context ('GET', function () {
    it ('should get all the rentals', async function () {
      // Send a mock request to the api, and wait for the response.
      const res = await request ()
        .post ('/api/rentals')
        .expect (200);
        
      // res.body has the text from the response. 
      // From here you can use chai to implement test oracle via assertions.
    });
  });
});
Resources & Resource Controller
mocha
superagent
chai