-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
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")
})
})
})
} Metadata
Metadata
Assignees
Labels
No labels