Automattic / Automattic/expect.js

retry until expectation meet or time out (async expectations)

Open
#21 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.1k
Forks
207
PR merge metrics
No merged PRs in 30d

Description

I'm using expect.js for UI testing with headless browser. Nasty problem - JS UI is asynchronous, with delays, smooth UI transitions and so on. So, when You click button - the actual action may take place not immediately but after 0.2sec.

It makes testing hard - You has to repeatedly check and wait for some conditions, and code becomes hairy. One possible solution - incorporate wait and retry logic directly into expectation library. For example, below are two versions of code that does the same thing.

First version opens profile dialog, waits for it and checks for some field inside of it.

``` JavaScript
client.click('Profile')
var condition = function(){return client.hasDialog('Profile')}
waitFor(condition, function(){
expect(client.text()).to.match(/Name:.*Jim Raynor/)
client.click('Messages')
...
})
```

But we can simplify it, we don't have to check explicitly for dialog to be opened, we can just check for what we are really interested in - presence of some specific field. So, we can rewritte `match` function to retry every 0.05sec and raise error only after 1sec timeout, and code will be greatly simplified:

``` JavaScript
client.click('Profile')
expect(client.text()).to.match(/Name:.*Jim Raynor/, function(){
client.click('Messages')
...
})
```

It seems that such functionality may be done as an addon to expect.js - by wrapping all terminal
functions like `match`, `eql`, `be`, ... with async wait & retry wrapper. What do You think?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.