Giter Site home page Giter Site logo

utgs's Issues

Improve tests for throwing errors

Currently the api only allows to test that a function throws an error if a particular type.

Due to limitations in AppsScripts, the test can fail even though an error is actually thrown, since the isinstance test fails. An error objected created in the utgs library won't be an instance of an error object in the main project.

Also, error messages should also be exposed via the api, so a test can be do based on the message.

`assert.throwsError` not recognizing thrown error

When testing that a constructor throws an error, the test fails with the message, No error was thrown, expecting error of type 'Error'. Checking err instanceof Error returns true in the console during function execution.

class MyClass {
  constructor(url) {
    let notAllowed = "api/v1";

    if(url.includes(notAllowed)) {
      let error = new Error('You can't do that');
      console.log(error instanceof Error) // => true
      throw error;
    }
  }
}

// Throws an Error in the console
function simple_test() {
  new MyClass("https://www.example.com/api/v1")
}


// Fails the unit test with "No error was thrown, expecting error of type 'Error'"
function utgsTest() {
  const { describe, it, assert } = Utgs.module()
  describe('A unit test', function() {
    it('will fail with a bad structure', function() {
      assert.throwsError("api/v1 in the URL", function() {
        new MyClass("https://www.example.com/api/v1")
      })
    })
  })
} 

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.