[gjs/wip/ptomato/classes: 8/11] tests: Add ES6 class inheriting from legacy class
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/classes: 8/11] tests: Add ES6 class inheriting from legacy class
- Date: Sat, 29 Jul 2017 08:13:51 +0000 (UTC)
commit a65755c99b3d40b4e1e570cf2cf224ac979220c2
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Jul 23 19:24:25 2017 -0700
tests: Add ES6 class inheriting from legacy class
This should be supported, so add tests for it.
installed-tests/js/testLegacyClass.js | 68 +++++++++++++++++++++++++++++++++
1 files changed, 68 insertions(+), 0 deletions(-)
---
diff --git a/installed-tests/js/testLegacyClass.js b/installed-tests/js/testLegacyClass.js
index 44fb3a4..6805532 100644
--- a/installed-tests/js/testLegacyClass.js
+++ b/installed-tests/js/testLegacyClass.js
@@ -660,3 +660,71 @@ describe('An interface', function () {
expect(AnInterface.toString()).toEqual('[interface Interface for AnInterface]');
});
});
+
+describe('ES6 class inheriting from Lang.Class', function () {
+ let Shiny, Legacy;
+
+ beforeEach(function () {
+ Legacy = new Lang.Class({
+ Name: 'Legacy',
+ _init(someval) {
+ this.constructorCalledWith = someval;
+ },
+
+ instanceMethod() {},
+ chainUpToMe() {},
+ overrideMe() {},
+
+ get property() { return this._property + 1; },
+ set property(value) { this._property = value - 2; },
+ });
+ Legacy.staticMethod = function () {};
+ spyOn(Legacy, 'staticMethod');
+ spyOn(Legacy.prototype, 'instanceMethod');
+ spyOn(Legacy.prototype, 'chainUpToMe');
+ spyOn(Legacy.prototype, 'overrideMe');
+
+ Shiny = class Shiny extends Legacy {
+ constructor(someval) {
+ super(someval);
+ }
+
+ chainUpToMe() { super.chainUpToMe(); }
+ overrideMe() {}
+ };
+ });
+
+ it('calls a static method on the parent class', function () {
+ Shiny.staticMethod();
+ expect(Legacy.staticMethod).toHaveBeenCalled();
+ });
+
+ it('calls a method on the parent class', function () {
+ let instance = new Shiny();
+ instance.instanceMethod();
+ expect(Legacy.prototype.instanceMethod).toHaveBeenCalled();
+ });
+
+ it("passes arguments to the parent class's constructor", function () {
+ let instance = new Shiny(42);
+ expect(instance.constructorCalledWith).toEqual(42);
+ });
+
+ it('chains up to a method on the parent class', function () {
+ let instance = new Shiny();
+ instance.chainUpToMe();
+ expect(Legacy.prototype.chainUpToMe).toHaveBeenCalled();
+ });
+
+ it('overrides a method on the parent class', function () {
+ let instance = new Shiny();
+ instance.overrideMe();
+ expect(Legacy.prototype.overrideMe).not.toHaveBeenCalled();
+ });
+
+ it('sets and gets a property from the parent class', function () {
+ let instance = new Shiny();
+ instance.property = 42;
+ expect(instance.property).toEqual(41);
+ });
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]