For unit testing with Mocha, do I explicitly have ...
# typescript
l
For unit testing with Mocha, do I explicitly have to use
pulumi.all(...).apply(callbackFn)
, or can I also use
someOutput.apply(callbackFn)
?
l
In what context? I use Mocha for all my unit testing and don't have much code like that...
The pattern in our mocha specs is: 1. Import chai-as-promised. 2. Add
promise()
to
Output
. 3. Write all expects thus:
return expect(myOutput.promise()).to.eventually.include(expectedValue)
For any assertions on an output / promise, note that the callback passed to
it()
needs to be
async
, and the result of the
expect()
needs to be returned from it.
The code for adding
promise()
to
Output
is:
Copy code
declare module '@pulumi/pulumi' {
  export interface OutputInstance<T> {
    promise(withUnknowns?: boolean): Promise<T>;
  }
}
l
@little-cartoon-10569 I eventually found it. The problem was in my mocks setup, rather than in the verification part with the callback.
👍 1
@little-cartoon-10569 do you have a public code example somewhere of the pattern (1-2-3) you described above?
l
I'll make a gist.
💯 1