intern-tutorial icon indicating copy to clipboard operation
intern-tutorial copied to clipboard

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

Open justinbc820 opened this issue 8 years ago • 3 comments

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

justinbc820 avatar Nov 21 '17 00:11 justinbc820

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 avatar Nov 21 '17 03:11 jason0x43

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 avatar Nov 21 '17 03:11 jason0x43

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.

jason0x43 avatar Nov 21 '17 03:11 jason0x43