So here's a complete Mocha/Chai based example that works and should show how you can implement a test like you are trying to:
const chai = require('chai');
const spies = require('chai-spies');
chai.use(spies);
const expect = chai.expect;
class ClassThatDoesStuff {
randomArray = [];
async doStuff() {
console.log('Do stuff...');
await new Promise((resolve) => setTimeout(resolve, 1000));
this.randomArray.push('random entry');
console.log('Done doing stuff');
}
}
describe('Async Function Testing', () => {
let objectThatDoesStuff = new ClassThatDoesStuff();
it('should do things', async () => {
const spy = chai.spy.on(objectThatDoesStuff, 'doStuff');
await objectThatDoesStuff.doStuff();
expect(spy).to.have.been.called();
expect(objectThatDoesStuff.randomArray).to.contain('random entry');
});
});
The most important point is: Before you assert that something was done by an asynchronous function, make sure to wait for that function to complete (in this case using await objectThatDoesStuff.doStuff(), in your case using await component.showSuccess()).
await component.showSuccess();awaitcomponent.showSuccess(). Also, you are expecting an assignment to a variable to be truthy. I don't know that that makes sense.