Skip to content

Commit

Permalink
chore: Migrate from moduleFor* syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
josemarluedke committed Aug 6, 2019
1 parent 9f6af93 commit c7d95b8
Show file tree
Hide file tree
Showing 13 changed files with 378 additions and 372 deletions.
9 changes: 0 additions & 9 deletions packages/-ember-decorators/tests/helpers/modules.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { module, test } from 'qunit';

module('Babel | decorators (legacy) and class properties together ');
module('Babel | decorators (legacy) and class properties together ', function() {
// This test more or less only checks, if the `@decorator` syntax can be used.

// This test more or less only checks, if the `@decorator` syntax can be used.
test('decorators inside class and class field work.', function(assert) {
function decorator(value) {
assert.strictEqual(value, 123);
return function() {};
}

test('decorators inside class and class field work.', function(assert) {
function decorator(value) {
assert.strictEqual(value, 123);
return function() {};
}
class Foo {
@decorator(123)
bar = 'baz'

class Foo {
@decorator(123)
bar = 'baz'
}

}

new Foo();
new Foo();
});
});

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { module, test } from 'qunit';

module('Babel | decorators (legacy)');
module('Babel | decorators (legacy)', function() {
// This test more or less only checks, if the `@decorator` syntax can be used.

// This test more or less only checks, if the `@decorator` syntax can be used.
test('it works', function(assert) {
function decorator(value) {
assert.strictEqual(value, 123);
return function() {};
}

test('it works', function(assert) {
function decorator(value) {
assert.strictEqual(value, 123);
return function() {};
}
@decorator(123)
class Foo {}

@decorator(123)
class Foo {}

new Foo();
new Foo();
});
});
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import { module, test } from 'qunit';

module('Babel | class properties');
module('Babel | class properties', function() {
test('it works', function(assert) {
// https://github.com/babel/babel/tree/6.x/packages/babel-plugin-transform-class-properties
class Bork {
//Property initializer syntax
instanceProperty = 'bork';
boundFunction = () => {
return this.instanceProperty;
};

test('it works', function(assert) {
// https://github.com/babel/babel/tree/6.x/packages/babel-plugin-transform-class-properties
class Bork {
//Property initializer syntax
instanceProperty = 'bork';
boundFunction = () => {
return this.instanceProperty;
};
//Static class properties
static staticProperty = 'babelIsCool';
static staticFunction = function() {
return Bork.staticProperty;
};
}

//Static class properties
static staticProperty = 'babelIsCool';
static staticFunction = function() {
return Bork.staticProperty;
};
}
const myBork = new Bork();

const myBork = new Bork();

assert.strictEqual(
myBork.__proto__.boundFunction,
undefined,
'Property initializers are not on the prototype.'
);
assert.strictEqual(
myBork.boundFunction.call(undefined),
'bork',
'Bound functions are bound to the class instance.'
);
assert.strictEqual(
Bork.staticFunction(),
'babelIsCool',
'Static function exists on the class.'
);
assert.strictEqual(
myBork.__proto__.boundFunction,
undefined,
'Property initializers are not on the prototype.'
);
assert.strictEqual(
myBork.boundFunction.call(undefined),
'bork',
'Bound functions are bound to the class instance.'
);
assert.strictEqual(
Bork.staticFunction(),
'babelIsCool',
'Static function exists on the class.'
);
});
});
101 changes: 52 additions & 49 deletions packages/-ember-decorators/tests/unit/component/attribute-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,77 @@ import { attribute } from '@ember-decorators/component';
import { computed } from '@ember/object';

import hbs from 'htmlbars-inline-precompile';
import { moduleForComponent } from 'ember-qunit';
import { test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { find, findAll } from 'ember-native-dom-helpers';

moduleForComponent('@attribute', { integration: true });
module('@attribute', function(hooks) {
setupRenderingTest(hooks);

test('decorator adds attributes to component', function(assert) {
class FooComponent extends Component {
@attribute role = 'button';
test('decorator adds attributes to component', async function(assert) {
class FooComponent extends Component {
@attribute role = 'button';

@attribute('data-foo') foo = 'lol';
@attribute('data-foo') foo = 'lol';

@attribute
@computed
get id() {
return 'bar';
@attribute
@computed
get id() {
return 'bar';
}
}
}

this.register('component:foo-component', FooComponent);
this.register('template:components/foo-component', hbs`Hello, world!`);
this.owner.register('component:foo-component', FooComponent);
this.owner.register('template:components/foo-component', hbs`Hello, world!`);

this.render(hbs`{{foo-component}}`);
await render(hbs`{{foo-component}}`);

assert.ok(find('[role="button"]'));
assert.ok(find('[data-foo="lol"]'));
assert.ok(find('#bar'));
});
assert.ok(find('[role="button"]'));
assert.ok(find('[data-foo="lol"]'));
assert.ok(find('#bar'));
});

test('decorator does not add attribute to superclass', function(assert) {
class FooComponent extends Component {
@attribute role = 'button';
}
test('decorator does not add attribute to superclass', async function(assert) {
class FooComponent extends Component {
@attribute role = 'button';
}

class BarComponent extends FooComponent {
@attribute id = 'bar';
}
class BarComponent extends FooComponent {
@attribute id = 'bar';
}

this.register('component:foo-component', FooComponent);
this.register('template:components/foo-component', hbs`Hello, world!`);
this.owner.register('component:foo-component', FooComponent);
this.owner.register('template:components/foo-component', hbs`Hello, world!`);

this.register('component:bar-component', BarComponent);
this.register('template:components/bar-component', hbs`Hello, moon!`);
this.owner.register('component:bar-component', BarComponent);
this.owner.register('template:components/bar-component', hbs`Hello, moon!`);

this.render(hbs`{{foo-component}}{{bar-component}}`);
await render(hbs`{{foo-component}}{{bar-component}}`);

assert.equal(findAll('[role="button"]').length, 2);
assert.equal(findAll('#bar').length, 1);
});

test('decorator works correctly through traditional and ES6 hierarchy', function(assert) {
const FooComponent = Component.extend({
attributeBindings: ['role'],
role: 'button',
assert.equal(findAll('[role="button"]').length, 2);
assert.equal(findAll('#bar').length, 1);
});

class BarComponent extends FooComponent {
@attribute id = 'bar';
}
test('decorator works correctly through traditional and ES6 hierarchy', async function(assert) {
const FooComponent = Component.extend({
attributeBindings: ['role'],
role: 'button',
});

class BarComponent extends FooComponent {
@attribute id = 'bar';
}

this.register('component:foo-component', FooComponent);
this.register('template:components/foo-component', hbs`Hello, world!`);
this.owner.register('component:foo-component', FooComponent);
this.owner.register('template:components/foo-component', hbs`Hello, world!`);

this.register('component:bar-component', BarComponent);
this.register('template:components/bar-component', hbs`Hello, moon!`);
this.owner.register('component:bar-component', BarComponent);
this.owner.register('template:components/bar-component', hbs`Hello, moon!`);

this.render(hbs`{{foo-component}}{{bar-component}}`);
await render(hbs`{{foo-component}}{{bar-component}}`);

assert.equal(findAll('[role="button"]').length, 2);
assert.equal(findAll('#bar').length, 1);
assert.equal(findAll('[role="button"]').length, 2);
assert.equal(findAll('#bar').length, 1);
});
});
Loading

0 comments on commit c7d95b8

Please sign in to comment.