classroomtechtools / utgs Goto Github PK
View Code? Open in Web Editor NEWUnit Testing for Google Appscripts
Unit Testing for Google Appscripts
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.
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")
})
})
})
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.