Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Commit

Permalink
feat(timeout): step() can flush the queue, fixes #76
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Feb 22, 2016
1 parent eb575f3 commit 36fbfdb
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,21 @@ tests: function (deps) {
}
```

Also flushed the `$timeout` service

```js
ngDescribe({
inject: '$timeout',
tests: function (deps) {
it(function () {
deps.$timeout(...)
deps.step();
// same as deps.$timeout.flush()
})
}
})
```

**root** - alternative context for BDD callbacks

Imagine we are loading Angular and ngDescribe in a synthetic browser environment (like
Expand Down
3 changes: 3 additions & 0 deletions dist/ng-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3464,6 +3464,9 @@ if (String(/a/mig) !== '/a/gim') {
if (dependencies.$rootScope) {
dependencies.$rootScope.$digest();
}
if (dependencies.$timeout) {
dependencies.$timeout.flush();
}
};
}

Expand Down
15 changes: 15 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,21 @@ tests: function (deps) {
}
```

Also flushed the `$timeout` service

```js
ngDescribe({
inject: '$timeout',
tests: function (deps) {
it(function () {
deps.$timeout(...)
deps.step();
// same as deps.$timeout.flush()
})
}
})
```

**root** - alternative context for BDD callbacks

Imagine we are loading Angular and ngDescribe in a synthetic browser environment (like
Expand Down
3 changes: 3 additions & 0 deletions src/ng-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@
if (dependencies.$rootScope) {
dependencies.$rootScope.$digest();
}
if (dependencies.$timeout) {
dependencies.$timeout.flush();
}
};
}

Expand Down
29 changes: 29 additions & 0 deletions test/issue-76-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* global describe, ngDescribe, it */
describe('issue 76 - deps.step and $timeout', function () {
ngDescribe({
name: 'step $timeout',
inject: '$timeout',
only: false,
tests: function (deps) {
it('advances $timeout using flush', function (done) {
deps.$timeout(done, 10000);
deps.$timeout.flush();
});

it('can flush the timeout using step()', function (done) {
deps.$timeout(done, 10000);
deps.step();
});
}
});

ngDescribe({
name: 'step $timeout shortcut',
tests: function ($timeout) {
it('advances $timeout using flush', function (done) {
$timeout(done, 10000);
$timeout.flush();
});
}
});
});

0 comments on commit 36fbfdb

Please sign in to comment.