Skip to content

Instantly share code, notes, and snippets.

@bastimeyer
Last active October 4, 2018 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastimeyer/b365ecfbc29444455d082cf1b295156b to your computer and use it in GitHub Desktop.
Save bastimeyer/b365ecfbc29444455d082cf1b295156b to your computer and use it in GitHub Desktop.
New Twiddle
import { module, test, todo } from "ember-qunit";
import EmberObject from "@ember/object";
import Mixin from "@ember/object/mixin";
module( "simple es6 classes with .extend", {
before() {
// Works
this.A = class A extends EmberObject {
foo = 1;
}
this.B = class B extends this.A {
foo = 2;
}
this.C = class C extends EmberObject.extend({ foo: 3 }) {}
this.D = class D extends EmberObject.extend( Mixin.create({ foo: 4 }) ) {}
// Extending native classes with Ember doesn't work in Ember >=3.2, even if
// https://ember-decorators.github.io/ember-decorators/latest/docs/native-class-basics#extending-native-classes-with-extend-
// claims that it's working.
this.E = class E extends this.A.extend({ foo: 5 }) {}
this.F = class F extends this.A.extend({ foo: 5 }) {
foo = 6;
}
this.G = class G extends this.A.extend( Mixin.create({ foo: 7 }) ) {}
this.H = class H extends this.A.extend( Mixin.create({ foo: 7 }) ) {
foo = 8;
}
}
});
test( "create", function( assert ) {
assert.strictEqual( this.A.create().foo, 1, "a.foo === 1" );
assert.strictEqual( this.B.create().foo, 2, "b.foo === 2" );
assert.strictEqual( this.C.create().foo, 3, "c.foo === 3" );
assert.strictEqual( this.D.create().foo, 4, "d.foo === 4" );
assert.strictEqual( this.E.create().foo, 5, "e.foo === 5" );
assert.strictEqual( this.F.create().foo, 6, "f.foo === 6" );
assert.strictEqual( this.G.create().foo, 7, "g.foo === 7" );
assert.strictEqual( this.H.create().foo, 8, "h.foo === 8" );
});
// optional test, as it's not officially supported
todo( "new", function( assert ) {
assert.strictEqual( new this.A().foo, 1, "a.foo === 1" );
assert.strictEqual( new this.B().foo, 2, "b.foo === 2" );
assert.strictEqual( new this.C().foo, 3, "c.foo === 3" );
assert.strictEqual( new this.D().foo, 4, "d.foo === 4" );
assert.strictEqual( new this.E().foo, 5, "e.foo === 5" );
assert.strictEqual( new this.F().foo, 6, "f.foo === 6" );
assert.strictEqual( new this.G().foo, 7, "g.foo === 7" );
assert.strictEqual( new this.H().foo, 8, "h.foo === 8" );
});
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-qunit';
import { assign } from '@ember/polyfills';
let attributes = assign({ rootElement: '#main' }, config.APP);
setApplication(Application.create(attributes));
start();
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": true
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment