theintern / intern-tutorial

Learn how to use Intern by following this tutorial!
http://theintern.io
144 stars 44 forks source link

Readme shows invalid function type passed to before block (functional tests) #39

Open justinbc820 opened 6 years ago

justinbc820 commented 6 years ago

Expected behavior

In the Readme, the before block in a functional suite should take a SuiteLifecycleFunction, which returns PromiseLike.

Current behavior

The readme shows the function passed to the before block returning Promise<Command, any>.

Possible solution

before(async ({ remote }) => {
    await remote
        .get('_dist/src/index.html')
        .setFindTimeout(5000)
        .findDisplayedByCssSelector('body.loaded');
});

/***** OR *****/

before(({ remote }) => {
    return remote
        .get('_dist/src/index.html')
        .setFindTimeout(5000)
        .findDisplayedByCssSelector('body.loaded')
        .end();
});

Steps to reproduce (for bugs)

no steps, just look in the readme. Typescript just complains about the wrong type being returned.

Environment

Example (e.g., dojo, backbone, etc.): Intern version: Node version: NPM version: Browser version:

Additional information

jason0x43 commented 6 years ago

Hmm...this is actually a bug (or at least an inconvenience) in the Intern typings. SuiteLifeCycleFunction shouldn't care about the resolution type of a Promise. findDisplayedByCssSelector returns essentially a PromiseLike<Element> which should be fine; all Intern really cares about is whether or not the return type is a PromiseLike so it knows whether to wait for it to resolve. However, the current typings explicitly expect a PromiseLike<void>.

I created https://github.com/theintern/intern/issues/845 to track this.

jason0x43 commented 6 years ago

This slipped through before because the completed tutorial uses async/await rather than explicitly returning a Command chain. Since no value is explicitly returned in the async/await version of the test, the function implicitly returns a PromiseLike<void>.

jason0x43 commented 6 years ago

Once a new version of Intern is published (likely 4.1.3), the tutorial will be updated to use it. Until then, using await or tacking a .end() or .then(() => {}) to the end of a Command chain will make TS happy.