Skip to content

Commit

Permalink
Closes softlayer#156
Browse files Browse the repository at this point in the history
  • Loading branch information
theoshu committed Nov 20, 2015
1 parent b0e1096 commit 97acf3f
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# sl-ember-test-helpers Changelog

### 1.10.0

* [#129](https://github.com/softlayer/sl-ember-test-helpers/issues/126) [ENHANCEMENT] Add globalLibraries helper

[View complete changeset](https://github.com/softlayer/sl-ember-test-helpers/compare/v1.9.0...v1.10.0)

### 1.9.0

* [#129](https://github.com/softlayer/sl-ember-test-helpers/issues/129) [BREAKING ENHANCEMENT] Upgrade to Ember CLI 1.13.8
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ The call to `requires` returns an object:
}
```

### Global Libraries

Use this helper to determine if a component called globally scoped Ember.$, $ or jQuery. You must wrap your component with references to the setup and removal functions.

```
globalLibraries.setupSpies();
this.subject();
globalLibraries.restoreSpies();
assert.strictEqual(
globalLibraries.called,
false,
'There are no references to Ember.$, $ or jQuery'
);
```

The call to `called` returns a boolean:

```
<boolean: true if the spy detects a reference to the global scope, false if not>
```

## Asynchronous

Expand Down
6 changes: 4 additions & 2 deletions test-support/helpers/sl/register-test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import Ember from 'ember';
import {
contains,
AjaxHelper,
requires
requires,
globalLibraries
} from './synchronous';

export default function() {
Ember.Test.registerHelper( 'contains', contains );
Ember.Test.registerHelper( 'Ajax', AjaxHelper );
Ember.Test.registerHelper( 'requires', requires );
}
Ember.Test.registerHelper( 'globalLibraries', globalLibraries );
}
6 changes: 4 additions & 2 deletions test-support/helpers/sl/synchronous.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import AjaxHelper from './synchronous/ajax';
import contains from './synchronous/contains';
import requires from './synchronous/requires';
import * as globalLibraries from './synchronous/global-libraries';

export {
AjaxHelper,
contains,
requires
};
requires,
globalLibraries
};
21 changes: 21 additions & 0 deletions test-support/helpers/sl/synchronous/global-libraries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Ember from 'ember';
import sinon from 'sinon';

export let called;
export let jqueryAliasSpy;
export let jquerySpy;
export let emberJquery;

export function setupSpies() {
jqueryAliasSpy = sinon.spy( window, '$' );
jquerySpy = sinon.spy( window, 'jQuery' );
emberJquery = sinon.spy( Ember, '$' );
}

export function restoreSpies() {
called = jqueryAliasSpy.called || jquerySpy.called || emberJquery.called;

window.$.restore();
window.jQuery.restore();
Ember.$.restore();
}
23 changes: 23 additions & 0 deletions tests/unit/helpers/sl/synchronous/global-libaries-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test } from 'ember-qunit';
import * as globalLibraries from '../../../../helpers/sl/synchronous/global-libraries';

module( 'Unit | Helpers | sl/synchronous/global-libraries' );

test( 'it exists', function( assert ) {
assert.ok(
globalLibraries,
'it exists'
);
});

test( 'Functions as expected', function( assert ) {
globalLibraries.setupSpies();

globalLibraries.restoreSpies();

assert.equal(
globalLibraries.called,
false,
'There are no references to Ember.$, $ or jQuery'
);
});

0 comments on commit 97acf3f

Please sign in to comment.