Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jwcnewton/async-jasmine
Async, Await for Jasmine
https://github.com/jwcnewton/async-jasmine
async async-jasmime await es8 jasmine
Last synced: 13 days ago
JSON representation
Async, Await for Jasmine
- Host: GitHub
- URL: https://github.com/jwcnewton/async-jasmine
- Owner: jwcnewton
- Created: 2017-10-27T07:31:55.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-02T16:14:18.000Z (about 7 years ago)
- Last Synced: 2024-10-10T14:26:57.371Z (2 months ago)
- Topics: async, async-jasmime, await, es8, jasmine
- Language: JavaScript
- Homepage:
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
async-jasmine
======Jasmine-async, wraps jasmine wrapCompare with asynchronous
functionality, **currently supporting browser**.Setting up jasmine-async
=========================You will need to include the script in the SpecRunner.html
```html```
To start testing asynchronously simply call:
```javascript
jasmine.AsyncTestMatcher.install();
```
And stop testing asynchronous call:
```javascript
jasmine.AsyncTestMatcher.uninstall();
```
It is important to call uninstall since calling install will replace
underlying prototype behaviour with asynchronous behaviour.We *can* use the standard matchers with the async wrap install, however
you might find unexpected behaviour since the default synchronous
behaviour has been tested by Jasmine (Pivotal Labs).Adding new matchers
===================To add new matchers simply extend the existing AsyncMatchers object with
new matchers following the jasmine standard for matchers:
```javascript
toEqualAsync: (util) => {
return {
compare: *(1)* async function (actual, expected) *(2)* {
var result = {
pass: false
};result.pass = util.equals(actual, expected); *(3)*
return result;
}
}
}
```
The current standard for adding new matchers is the append “Async” to
the name of the matcher we need to do this since the wrap won’t await
the expected function if the name doesn’t contain Async this is also
case sensitive
```javascript
if (name.indexOf('Async') !== -1) {
result = await matcherCompare.apply(null, args);
} else {
result = matcherCompare.apply(null, args);
}
```
1. It you don’t have to add async if you are not awaiting a result.2. You’re compare function will take an actual and an
expected argument.3. You can call util.equals or evaluate the result yourself.
Known issues
============This currently doesn’t work with node js but it has been written in a
way that could be extended to work with the require js (AMD)Calling **.not** on non-asynchronous assertions while the asynchronous wrap
is installed will cause a false resultExample:
```javascript
it("jam", (); {
//Assert
expect("jam").toEqual("jam");
}); //PASSit("jam", () => {
//Assert
expect("jam").not.toEqual("jams");
}); //FAIL
```
There is currently a work around for the toEqual operator
```javascript
it("jam", async (done) => {
//Assert
await expect("jam").not.toEqualAsync("jams");
done();
}); //PASS
```
### Support- [x] Browser
- [ ] Node