https://pulumi.com logo
#typescript
Title
# typescript
l

limited-rainbow-51650

11/02/2021, 11:10 AM
For unit testing with Mocha, do I explicitly have to use
pulumi.all(...).apply(callbackFn)
, or can I also use
someOutput.apply(callbackFn)
?
l

little-cartoon-10569

11/02/2021, 8:05 PM
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

limited-rainbow-51650

11/03/2021, 11:06 AM
@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

little-cartoon-10569

11/09/2021, 7:06 PM
I'll make a gist.
💯 1