Skip to content

Commit

Permalink
Default useEvalAsync to false while testing
Browse files Browse the repository at this point in the history
This makes it easier to for users to test listenTo interactions since a
digest does not have to be forced for every test.
  • Loading branch information
jrust committed Feb 27, 2017
1 parent c18de65 commit 80b2718
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flux-angular",
"version": "3.1.2",
"version": "3.1.3",
"main": "release/flux-angular.js",
"ignore": [
"**/.*",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flux-angular",
"version": "3.1.2",
"version": "3.1.3",
"description": "A FLUX architecture for Angular JS",
"main": "./src/flux-angular.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions release/flux-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -4798,6 +4798,8 @@ angular.module('flux', []).provider('flux', function FluxProvider() {
}];
}).run(['$rootScope', '$injector', 'flux', function ($rootScope, $injector, flux) {
if (angular.mock) {
// Forced to false during testing to avoid needing to flush to test $listenTo interaction
useEvalAsync = false;
flux.reset();
}

Expand Down
2 changes: 1 addition & 1 deletion release/flux-angular.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/flux-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ angular.module('flux', [])
})
.run(['$rootScope', '$injector', 'flux', function ($rootScope, $injector, flux) {
if (angular.mock) {
// Forced to false during testing to avoid needing to flush to test $listenTo interaction
useEvalAsync = false;
flux.reset();
}

Expand Down
11 changes: 7 additions & 4 deletions tests/flux-angular-spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
describe('FLUX-ANGULAR', function() {
describe('.store', function() {
let $scope, flux, cb, MyStore, MyStoreB, $browser;
let $scope, flux, fluxProvider, cb, MyStore, MyStoreB, $browser;

function initialize (options) {
options = options || {};

angular.module('test', ['flux'])
.config(function (fluxProvider) {
.config(function (_fluxProvider_) {
fluxProvider = _fluxProvider_;
fluxProvider.setImmutableDefaults({ asynchronous: false });
if(angular.isDefined(options.useEvalAsync)) {
fluxProvider.useEvalAsync(options.useEvalAsync);
Expand Down Expand Up @@ -115,7 +116,6 @@ describe('FLUX-ANGULAR', function() {
$scope.$listenTo(MyStore, cb);
flux.dispatcher.storeInstances.MyStore.initialize();
flux.dispatch('addItem', { item: 'foo' });
$browser.defer.flush();
expect(cb.calls.count()).toEqual(3); // once for initialization, once for state reset, and once for addItem
});
});
Expand Down Expand Up @@ -149,6 +149,10 @@ describe('FLUX-ANGULAR', function() {
});

describe('event listeners', function() {
beforeEach(function() {
fluxProvider.useEvalAsync(true); // for to true because default is to turn it off for tests
});

it('should have a $listenTo method', function() {
expect($scope.$listenTo).toBeDefined();
});
Expand Down Expand Up @@ -217,7 +221,6 @@ describe('FLUX-ANGULAR', function() {
cb.calls.reset();

flux.dispatch('addItem', { item: 'test' });
$browser.defer.flush();
expect(cb.calls.argsFor(0)[0]).toEqual('MyStore');
expect(cb.calls.argsFor(1)[0]).toEqual('MyStoreB');
});
Expand Down

0 comments on commit 80b2718

Please sign in to comment.