Questions tagged [node-assert]
6 questions
6
votes
2 answers
Mocha / Node: how to use assert.rejects()?
I tried to followed the documentation in order to test for the error message using assert.rejects (I do have Node above v10).
But it's always passing, even with a ridiculous message. What am I doing wrong?
it("should fail but it's not",
async…

João Otero
- 948
- 1
- 15
- 30
5
votes
2 answers
node assert: Test error message
Using node's assert module how can I test the message of an error?
throw new Error('Email is required!');
I'm using assert.throws to check if an error was thrown:
assert.throws(myFunction, Error);
But this does not provide the ability to check the…

mosquito87
- 4,270
- 11
- 46
- 77
3
votes
1 answer
AssertionError: Missing expected exception when testing async requirejs call using mocha
I'm writing a test for my custom requirejs loader. On malformed input it it supposed to throw an error.
I'm using mocha and plain node-assert to test it like this:
it('throws a SyntaxError on malformed input', function(done){
…

m90
- 11,434
- 13
- 62
- 112
2
votes
2 answers
How to assert that function throws with a specific error message
I'm using Node v18 ( with the built-in testrunner) and the package assert/strict to test that a function call throws an error with a custom error message.
I think my code should look like
assert.throws(() => myFunction(), 'content of error.message…
user19025657
0
votes
1 answer
Unexpected result from assert.fail
I'm using the assert module for throwing pre-condition errors. It seems to me based on the documentation that assert.fail(message) should throw an exception for which the message property is just the message passed in. However, it's being set to…

Becca Dee
- 1,530
- 1
- 24
- 51
0
votes
2 answers
Prototype function overriden by other "class"
I have the following inputModel:
var UserCreateInputModel = function(req) {
...
this.password = req.body.password;
this.repeatPassword = req.body.repeatPassword;
...
console.log(this.password !== this.repeatPassword);
…

mosquito87
- 4,270
- 11
- 46
- 77