Giter Site home page Giter Site logo

pesto-test-basics's Introduction

PESTO

Questions:

Instructions:

All the answers should be written in proper English.


1) Why should we write tests?

2) How much code coverage is required? Comment.

3) What kind of test is this? Explain your choice of answer.

Options:

  • End to end (E2E)

  • Integration

  • Unit

      var request = require('supertest');
      var app = require('../server');
    
      describe('API Tests', function() {
        var task  = {
          name: 'test',
        };
    
        describe('Get all tasks', function() {
          it('should get all tasks', function(done) {
            request(app)
              .get('/tasks')
              .end(function(err, res) {
                expect(res.statusCode).toBe(200);
                expect(Array.isArray(res.body)).toBe(true);
                done();
              });
          });
        });
    
        describe('Create task ', function() {
          it('should create a task', function(done) {
            request(app)
              .post('/tasks')
              .send(task)
              .end(function(err, res) {
                expect(res.statusCode).toBe(200);
                expect(res.body.name).toBe('test');
                task = res.body;
                done();
              });
          });
        });
      });

4) Below are 2 snippets of code which achieve the same functionality. Which snippet of code is better testable and WHY?

  // 1
  function valIncrementer(val, disabled) {
    var nextVal = val + 1;
    function clipToUpperLimit() {
      if (val >= 10) {
        nextVal = 10;
        secondStageSetter()
      }
    }
    function clipToLowerLimit() {
      if (val <= 0) {
        nextVal = 0;
        secondStageSetter()
      }
    }
    function secondStageSetter() {
      if (disabled) {
        nextVal = val
      }
    }
    function run() {
      clipToUpperLimit()
      clipToLowerLimit()
    }
    run()
    return nextVal
  }

  // 2
  const incrementedVal = (val) => val + 1;
  function substituteVal(val, low, high) {
    if (val >= high) return high
    else if (val <= low) return low
    else return val
  }
  function shouldIncrement(val, disabled) {
    return val >= 0 && val < 10 && !disabled
  }
  function valIncrementer(val, disabled) {
    if (shouldIncrement(val, disabled)) {
      return incrementedVal(val)
    }
    return substituteVal(val, 0, 10)
  }

5) Describe the difference between the two tests below. Which one is ideal and WHY?

    // 1
    it('should send the profile data to the server and update the profile view properly', function() {
      expect(...)to(...);
      expect(...)to(...);
    });

    // 2
    it('should send the profile data to the server', function() {
      expect(...)to(...);
    });

    it('should update the profile view properly', function() {
      expect(...)to(...);
    });

pesto-test-basics's People

Contributors

anshurathee avatar salhotra avatar arfatsalman avatar

Watchers

James Cloos avatar Kundan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.