Skip to content
Advertisement

Tag: testing

Mocha test false assert timeouts

I have some problem with my async mocha tests. The assert method within a promise results in a timeout when the input evaluates to false. (with true values it works fine) This is a simplified version of the problem. We usually do networking instead of this constructed promise. Answer You’d better NOT use async/await syntax on the promise constructor. It’s

Console.log from a class’ function

I want to test if my function inside my class returns the given sentence. But if I try to test using console.log, it returns ReferenceError: rev is not defined. What am I doing wrong? I’m a fairly new programmer, so bear with me if this is a stupid question. Answer The entire point of a class is to provide a

How to test method called in promise

I have a function that saves an entity and in the promise i want to check the delete is called. In my jest test it whizzes past and can’t think how to test it Here is the partial snippets, it all works, Promises called etc. just can’t figure how to test that ‘deleteMessage’ is called In my test i use

How to mock/spy useState hook in jest?

I am trying to spy on useState React hook but i always get the test failed This is my React component: counter.test.js: Unfortunately this doesn’t work and i get the test failed with that message: Answer You need to use React.useState instead of the single import useState. I think is about how the code gets transpiled, as you can see

node.js mocha before function runs after test execution

I have moved this around so much and tried with done(), asyncand chaining then(), moving the describe() around and my latest attempt was to return a promise in the before as Async function in mocha before() is alway finished before it() spec? suggested. The console.log(‘finished!’) that indicates the tables have been created is printed way after console.log(‘starting tests’) that indicates

Advertisement