0

I am getting a failed result in test cases which is caused by an await keyword not taking effect. The warning i am getting is 'await' has no effect on the type of this expression.ts(80007) and the code for that function which uses chai library is

describe("Add Task", function() {
    it("Should emit AddTask Event", async () => {
        let task = {
            'taskText':"New task",
            'isDeleted': false,
        };
        await expect(taskContract.addTask(task.taskText, task.isDeleted)
            .to.emit(taskContract,"AddTask")
            .withArgs(owner.address,total_tasks));
        
    });
});` 

I tried making the async function a normal function without arrow but it does'nt work.

  • Does this answer your question? https://stackoverflow.com/questions/45466040/verify-that-an-exception-is-thrown-using-mocha-chai-and-async-await – Lin Du Jan 20 '23 at 05:33

1 Answers1

0

That's because expect doesn't return a promise, but only promises can be awaited

Remove await and async

Konrad
  • 21,590
  • 4
  • 28
  • 64
  • after removing allso i am getting the error :- TypeError: Cannot read properties of undefined (reading 'emit') – 1181_Rahul Guha Jan 19 '23 at 18:59
  • 1
    @1181_RahulGuha `to` is a property of the return value of `expect`, not of `taskContract.addTask`. Your `)` is misplaced. – Sebastian Simon Jan 19 '23 at 19:15
  • 1
    Actually, any value can be awaited. It's one of the neat things about `async`/`await`. It's the `async`/`await` equivalent of wrapping something in `Promise.resolve` to normalize it to a Promise so that you can always call `.then` on it. But, as `expect` _never_ returns a Promise, the `await` is pointless in this case, which is why you are getting a warning. – Darryl Noakes Jan 19 '23 at 19:45