Permalink
Browse files

fix(decorators): properly decorates the constructor and uses useView

  • Loading branch information...
bas080
bas080 committed Jun 3, 2016
1 parent efd2c29 commit 1ab6864cffe335a20b4890ecdc8fa57a035f8b27
Showing with 34 additions and 7 deletions.
  1. +1 −0 config.js
  2. +1 −0 package.json
  3. +6 −2 src/decorators/resolved-view.js
  4. +7 −0 test/unit/aurelia-view.spec.js
  5. +19 −5 test/unit/resolved-view-decorator.spec.js
@@ -10,6 +10,7 @@ System.config({
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.0.0-beta.1.2.3",
"aurelia-framework": "npm:aurelia-framework@1.0.0-beta.1.2.5",
"aurelia-polyfills": "npm:aurelia-polyfills@1.0.0-beta.1.1.6",
"aurelia-templating": "npm:aurelia-templating@1.0.0-beta.1.2.7",
"babel": "npm:babel-core@5.8.38",
"babel-runtime": "npm:babel-runtime@5.8.38",
"core-js": "npm:core-js@1.2.6",
@@ -71,6 +71,7 @@
},
"dependencies": {
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@^1.0.0-beta.1.2.3",
"aurelia-templating": "npm:aurelia-templating@^1.0.0-beta.1.2.7",
"extend": "npm:extend@^3.0.0"
},
"devDependencies": {
@@ -1,11 +1,15 @@
import {Container} from 'aurelia-dependency-injection';
import {ViewManager} from './../view-manager';
import {useView} from 'aurelia-templating';
export function resolvedView(namespace, view) {
return function resolvedViewDecorator(target) {
let viewManager = Container.instance.get(ViewManager);
target.getViewStrategy = viewManager.resolve(namespace, view);
return target; /* handy for testing */
target.prototype.getViewStrategy = viewManager.resolve.bind(viewManager, namespace, view);
useView(viewManager.resolve(namespace, view))(target);
return target;
};
}
@@ -0,0 +1,7 @@
import * as exports from '../../src/aurelia-view';
describe('aurelia-view-manager', () => {
it('exports all the required things', () => {
});
});
@@ -1,22 +1,36 @@
import {resolvedView} from './../../src/decorators/resolved-view.js';
import {ViewManager} from './../../src/view-manager';
import {Container} from 'aurelia-dependency-injection';
describe('resolvedView', () => {
let container;
let fake;
class Fake {}
beforeEach(() => {
container = new Container().makeGlobal();
fake = new Fake();
});
it('sets the getViewStrategy property', () => {
/* is higher order */
expect(fake.getViewStrategy).toBeUndefined(); /* first it is undefined */
expect(typeof resolvedView('namespace', 'view')).toBe('function'); /* then it is set */
expect(resolvedView('namespace', 'view')(fake).getViewStrategy).toBeDefined();
it('calls the resolve method', () => {
let viewManager = Container.instance.get(ViewManager);
spyOn(viewManager, 'resolve');
resolvedView('hello', 'world')(Fake);
expect(viewManager.resolve).toHaveBeenCalled();
});
it('decorates the constructor', () => {
expect(resolvedView('namespace', 'view')(Fake).prototype.getViewStrategy).toBeDefined();
});
it('resolvedView is a higher order function', () => {
expect(typeof resolvedView('namespace', 'view')).toBe('function');
});
it('sets the getViewStrategy property on the instance', () => {
expect(fake.getViewStrategy).toBeDefined();
});
});

0 comments on commit 1ab6864

Please sign in to comment.