It's an anti pattern because we'll lose the handle to the promise. And if try to await or catch the promise, it's a race condition - promise may already resolved when you try to await for it. In practice, this sometimes causes an "Unhandled Promise" error throwed several seconds after user calls Workspace.init, which is very confusing.
The better way is to make the factory method Workspace.init returns a promise. And in test file's beforeAll block, await Workspace.init.
It's an anti pattern because we'll lose the handle to the promise. And if try to await or catch the promise, it's a race condition - promise may already resolved when you try to await for it. In practice, this sometimes causes an "Unhandled Promise" error throwed several seconds after user calls
Workspace.init
, which is very confusing.The better way is to make the factory method
Workspace.init
returns a promise. And in test file'sbeforeAll
block,await Workspace.init
.