Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit eb4bf1b

Browse files
committed
Merge pull request #49 from rodyhaddad/test/section-super-constructor
test(injector): wrap super constructor tests in describe group
2 parents e72d652 + e678c69 commit eb4bf1b

1 file changed

Lines changed: 64 additions & 58 deletions

File tree

test/injector.spec.js

Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -205,84 +205,90 @@ describe('injector', function() {
205205
});
206206

207207

208-
it('should support "super" to call a parent constructor', function() {
209-
class Something {}
208+
describe('SuperConstructor', function () {
210209

211-
@Inject(Something)
212-
class Parent {
213-
constructor(something) {
214-
this.parentSomething = something;
210+
211+
it('should support "super" to call a parent constructor', function() {
212+
class Something {}
213+
214+
@Inject(Something)
215+
class Parent {
216+
constructor(something) {
217+
this.parentSomething = something;
218+
}
215219
}
216-
}
217220

218-
@Inject(SuperConstructor, Something)
219-
class Child extends Parent {
220-
constructor(superConstructor, something) {
221-
superConstructor();
222-
this.childSomething = something;
221+
@Inject(SuperConstructor, Something)
222+
class Child extends Parent {
223+
constructor(superConstructor, something) {
224+
superConstructor();
225+
this.childSomething = something;
226+
}
223227
}
224-
}
225228

226-
var injector = new Injector();
227-
var instance = injector.get(Child);
229+
var injector = new Injector();
230+
var instance = injector.get(Child);
228231

229-
expect(instance.parentSomething).toBeInstanceOf(Something);
230-
expect(instance.childSomething).toBeInstanceOf(Something);
231-
expect(instance.childSomething).toBe(instance.parentSomething);
232-
});
232+
expect(instance.parentSomething).toBeInstanceOf(Something);
233+
expect(instance.childSomething).toBeInstanceOf(Something);
234+
expect(instance.childSomething).toBe(instance.parentSomething);
235+
});
233236

234237

235-
it('should support "super" to call multiple parent constructors', function() {
236-
class Foo {}
237-
class Bar {}
238+
it('should support "super" to call multiple parent constructors', function() {
239+
class Foo {}
240+
class Bar {}
238241

239-
@Inject(Foo)
240-
class Parent {
241-
constructor(foo) {
242-
this.parentFoo = foo;
242+
@Inject(Foo)
243+
class Parent {
244+
constructor(foo) {
245+
this.parentFoo = foo;
246+
}
243247
}
244-
}
245248

246-
@Inject(SuperConstructor, Foo)
247-
class Child extends Parent {
248-
constructor(superConstructor, foo) {
249-
superConstructor();
250-
this.childFoo = foo;
249+
@Inject(SuperConstructor, Foo)
250+
class Child extends Parent {
251+
constructor(superConstructor, foo) {
252+
superConstructor();
253+
this.childFoo = foo;
254+
}
251255
}
252-
}
253256

254-
@Inject(Bar, SuperConstructor, Foo)
255-
class GrandChild extends Child {
256-
constructor(bar, superConstructor, foo) {
257-
superConstructor();
258-
this.grandChildBar = bar;
259-
this.grandChildFoo = foo;
257+
@Inject(Bar, SuperConstructor, Foo)
258+
class GrandChild extends Child {
259+
constructor(bar, superConstructor, foo) {
260+
superConstructor();
261+
this.grandChildBar = bar;
262+
this.grandChildFoo = foo;
263+
}
260264
}
261-
}
262265

263-
var injector = new Injector();
264-
var instance = injector.get(GrandChild);
266+
var injector = new Injector();
267+
var instance = injector.get(GrandChild);
265268

266-
expect(instance.parentFoo).toBeInstanceOf(Foo);
267-
expect(instance.childFoo).toBeInstanceOf(Foo);
268-
expect(instance.grandChildFoo).toBeInstanceOf(Foo);
269-
expect(instance.grandChildBar).toBeInstanceOf(Bar);
270-
});
269+
expect(instance.parentFoo).toBeInstanceOf(Foo);
270+
expect(instance.childFoo).toBeInstanceOf(Foo);
271+
expect(instance.grandChildFoo).toBeInstanceOf(Foo);
272+
expect(instance.grandChildBar).toBeInstanceOf(Bar);
273+
});
271274

272275

273-
it('should throw an error when used in a factory function', function() {
274-
class Something {}
276+
it('should throw an error when used in a factory function', function() {
277+
class Something {}
278+
279+
@Provide(Something)
280+
@Inject(SuperConstructor)
281+
function createSomething(parent) {
282+
console.log('init', parent)
283+
}
284+
285+
expect(function() {
286+
var injector = new Injector([createSomething]);
287+
injector.get(Something);
288+
}).toThrowError(/Only classes with a parent can ask for SuperConstructor!/);
289+
});
275290

276-
@Provide(Something)
277-
@Inject(SuperConstructor)
278-
function createSomething(parent) {
279-
console.log('init', parent)
280-
}
281291

282-
expect(function() {
283-
var injector = new Injector([createSomething]);
284-
injector.get(Something);
285-
}).toThrowError(/Only classes with a parent can ask for SuperConstructor!/);
286292
});
287293

288294

0 commit comments

Comments
 (0)