Angular and Node Testing

Objectives

  • Discuss some tools you can use to test an Angular/Node app

Tools

  • Java
  • Node 4.2
  • Protractor.js
    • Webdriver Manager
  • Jasmine
  • Supertest

Protractor.js

Protractor runs tests against your application running in a real browser, interacting with it as a user would.

Protractor.js

  • Installs WebDriver Manager with it
    • Starts a Selenium server that can interact with your browser through HTTP commands (browser automation)
describe('Users', function() {
  describe('login', function() {
    it('should have username and password form', function() {
      browser.get('/login');
      var emailInput = element(by.id('username'));
      var passwordInput = element(by.id('password'));

      expect(emailInput.isPresent()).toBeTruthy();
      expect(passwordInput.isPresent()).toBeTruthy();
    });
  });
});

Jasmine

Jasmine is a behavior-driven development framework for testing JavaScript code.

Jasmine & Supertest

  • Supertest makes requests to your browser so you can test the server's response with Jasmine
var request = require('supertest')(app)


describe("users", function() {
  describe("signup", function() {
    it("should return 400 if there is no username", function(done) {
      request.post('/api/users/signup')
        .set('x-requested-with', 'XMLHttpRequest')
        .send({password: "testing"})
        .expect(400)
        .end(function(err, res) {
          if (err) return done.fail(err);
          done();
        });
    });
  });
});
Made with Slides.com