diff --git a/README.md b/README.md index 24f2a9f..3333f37 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dist/ng-describe.js b/dist/ng-describe.js index 199fb00..a12ad95 100644 --- a/dist/ng-describe.js +++ b/dist/ng-describe.js @@ -3464,6 +3464,9 @@ if (String(/a/mig) !== '/a/gim') { if (dependencies.$rootScope) { dependencies.$rootScope.$digest(); } + if (dependencies.$timeout) { + dependencies.$timeout.flush(); + } }; } diff --git a/docs/api.md b/docs/api.md index 13cea05..cefd6f7 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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 diff --git a/src/ng-describe.js b/src/ng-describe.js index 988f4ff..96af486 100644 --- a/src/ng-describe.js +++ b/src/ng-describe.js @@ -458,6 +458,9 @@ if (dependencies.$rootScope) { dependencies.$rootScope.$digest(); } + if (dependencies.$timeout) { + dependencies.$timeout.flush(); + } }; } diff --git a/test/issue-76-spec.js b/test/issue-76-spec.js new file mode 100644 index 0000000..5c5b6df --- /dev/null +++ b/test/issue-76-spec.js @@ -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(); + }); + } + }); +});