Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work towards using QUnit 2 APIs. #16061

Merged
merged 5 commits into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class LifeCycleHooksTest extends RenderingTest {
this.teardownAssertions = [];
}

teardown() {
super.teardown();
afterEach() {
super.afterEach();

for (let i = 0; i < this.teardownAssertions.length; i++) {
this.teardownAssertions[i]();
Expand Down
8 changes: 4 additions & 4 deletions packages/ember-metal/tests/accessors/get_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ moduleFor('Ember.get', class extends AbstractTestCase {
// BUGS
//

['@test (regression) watched properties on unmodified inherited objects should still return their original value']() {
['@test (regression) watched properties on unmodified inherited objects should still return their original value'](assert) {
let MyMixin = Mixin.create({
someProperty: 'foo',
propertyDidChange: observer('someProperty', () => {})
Expand All @@ -127,7 +127,7 @@ moduleFor('Ember.get', class extends AbstractTestCase {
let baseObject = MyMixin.apply({});
let theRealObject = Object.create(baseObject);

equal(get(theRealObject, 'someProperty'), 'foo', 'should return the set value, not false');
assert.equal(get(theRealObject, 'someProperty'), 'foo', 'should return the set value, not false');
}
});

Expand Down Expand Up @@ -160,7 +160,7 @@ moduleFor('Ember.getWithDefault', class extends AbstractTestCase {
let obj = {
count: 0,
unknownProperty(key) {
equal(key, 'foo', 'should pass key');
assert.equal(key, 'foo', 'should pass key');
this.count++;
return 'FOO';
}
Expand All @@ -174,7 +174,7 @@ moduleFor('Ember.getWithDefault', class extends AbstractTestCase {
let obj = {
unknownProperty(key) {
if (key === 'foo') {
equal(key, 'foo', 'should pass key');
assert.equal(key, 'foo', 'should pass key');
return 'FOO';
}
}
Expand Down
16 changes: 8 additions & 8 deletions packages/ember-metal/tests/accessors/mandatory_setters_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if (MANDATORY_SETTER) {
}

['@test should not setup mandatory-setter if property is not writable'](assert) {
expect(6);
assert.expect(6);

let obj = { };

Expand All @@ -62,7 +62,7 @@ if (MANDATORY_SETTER) {
}

['@test should not teardown non mandatory-setter descriptor'](assert) {
expect(1);
assert.expect(1);

let obj = { get a() { return 'hi'; } };

Expand All @@ -73,7 +73,7 @@ if (MANDATORY_SETTER) {
}

['@test should not confuse non descriptor watched gets'](assert) {
expect(2);
assert.expect(2);

let obj = { get a() { return 'hi'; } };

Expand All @@ -83,7 +83,7 @@ if (MANDATORY_SETTER) {
}

['@test should not setup mandatory-setter if setter is already setup on property'](assert) {
expect(2);
assert.expect(2);

let obj = { someProp: null };

Expand Down Expand Up @@ -119,7 +119,7 @@ if (MANDATORY_SETTER) {
}

['@test should not setup mandatory-setter if setter is already setup on property in parent prototype'](assert) {
expect(2);
assert.expect(2);

function Foo() { }

Expand All @@ -142,7 +142,7 @@ if (MANDATORY_SETTER) {
}

['@test should not setup mandatory-setter if setter is already setup on property in grandparent prototype'](assert) {
expect(2);
assert.expect(2);

function Foo() { }

Expand All @@ -169,7 +169,7 @@ if (MANDATORY_SETTER) {
}

['@test should not setup mandatory-setter if setter is already setup on property in great grandparent prototype'](assert) {
expect(2);
assert.expect(2);

function Foo() { }

Expand Down Expand Up @@ -350,7 +350,7 @@ if (MANDATORY_SETTER) {
}

['@test sets up mandatory-setter if property comes from prototype'](assert) {
expect(2);
assert.expect(2);

let obj = {
someProp: null,
Expand Down
52 changes: 25 additions & 27 deletions packages/ember-metal/tests/alias_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import {
let obj, count;

QUnit.module('ember-metal/alias', {
setup() {
beforeEach() {
obj = { foo: { faz: 'FOO' } };
count = 0;
},
teardown() {
afterEach() {
obj = null;
}
});
Expand All @@ -26,18 +26,18 @@ function incrementCount() {
count++;
}

QUnit.test('should proxy get to alt key', function() {
QUnit.test('should proxy get to alt key', function(assert) {
defineProperty(obj, 'bar', alias('foo.faz'));
equal(get(obj, 'bar'), 'FOO');
assert.equal(get(obj, 'bar'), 'FOO');
});

QUnit.test('should proxy set to alt key', function() {
QUnit.test('should proxy set to alt key', function(assert) {
defineProperty(obj, 'bar', alias('foo.faz'));
set(obj, 'bar', 'BAR');
equal(get(obj, 'foo.faz'), 'BAR');
assert.equal(get(obj, 'foo.faz'), 'BAR');
});

QUnit.test('old dependent keys should not trigger property changes', function() {
QUnit.test('old dependent keys should not trigger property changes', function(assert) {
let obj1 = Object.create(null);
defineProperty(obj1, 'foo', null, null);
defineProperty(obj1, 'bar', alias('foo'));
Expand All @@ -46,17 +46,17 @@ QUnit.test('old dependent keys should not trigger property changes', function()
addObserver(obj1, 'baz', incrementCount);

set(obj1, 'foo', 'FOO');
equal(count, 1);
assert.equal(count, 1);

removeObserver(obj1, 'baz', incrementCount);

set(obj1, 'foo', 'OOF');
equal(count, 1);
assert.equal(count, 1);
});

QUnit.test(`inheriting an observer of the alias from the prototype then
redefining the alias on the instance to another property dependent on same key
does not call the observer twice`, function() {
does not call the observer twice`, function(assert) {
let obj1 = Object.create(null);

meta(obj1).proto = obj1;
Expand All @@ -70,43 +70,41 @@ QUnit.test(`inheriting an observer of the alias from the prototype then
defineProperty(obj2, 'baz', alias('bar')); // override baz

set(obj2, 'foo', 'FOO');
equal(count, 1);
assert.equal(count, 1);

removeObserver(obj2, 'baz', incrementCount);

set(obj2, 'foo', 'OOF');
equal(count, 1);
assert.equal(count, 1);
});

QUnit.test('an observer of the alias works if added after defining the alias', function() {
QUnit.test('an observer of the alias works if added after defining the alias', function(assert) {
defineProperty(obj, 'bar', alias('foo.faz'));
addObserver(obj, 'bar', incrementCount);
ok(isWatching(obj, 'foo.faz'));
assert.ok(isWatching(obj, 'foo.faz'));
set(obj, 'foo.faz', 'BAR');
equal(count, 1);
assert.equal(count, 1);
});

QUnit.test('an observer of the alias works if added before defining the alias', function() {
QUnit.test('an observer of the alias works if added before defining the alias', function(assert) {
addObserver(obj, 'bar', incrementCount);
defineProperty(obj, 'bar', alias('foo.faz'));
ok(isWatching(obj, 'foo.faz'));
assert.ok(isWatching(obj, 'foo.faz'));
set(obj, 'foo.faz', 'BAR');
equal(count, 1);
assert.equal(count, 1);
});

QUnit.test('object with alias is dirtied if interior object of alias is set after consumption', function () {
QUnit.test('object with alias is dirtied if interior object of alias is set after consumption', function(assert) {
defineProperty(obj, 'bar', alias('foo.faz'));
get(obj, 'bar');
assertDirty(obj, () => set(obj, 'foo.faz', 'BAR'), 'setting the aliased key should dirty the object');

let tag = tagFor(obj);
let tagValue = tag.value();
set(obj, 'foo.faz', 'BAR');

assert.ok(!tag.validate(tagValue), 'setting the aliased key should dirty the object');
});

QUnit.test('setting alias on self should fail assertion', function() {
expectAssertion(() => defineProperty(obj, 'bar', alias('bar')), 'Setting alias \'bar\' on self');
});

function assertDirty(obj, callback, label) {
let tag = tagFor(obj);
let tagValue = tag.value();
callback();
ok(!tag.validate(tagValue), label);
}
28 changes: 15 additions & 13 deletions packages/ember-metal/tests/binding/connect_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,34 @@ function performTest(binding, a, b, get, set, connect) {
connect = () => binding.connect(a);
}

ok(!run.currentRunLoop, 'performTest should not have a currentRunLoop');
let { assert } = QUnit.config.current;

equal(get(a, 'foo'), 'FOO', 'a should not have changed');
equal(get(b, 'bar'), 'BAR', 'b should not have changed');
assert.ok(!run.currentRunLoop, 'performTest should not have a currentRunLoop');

assert.equal(get(a, 'foo'), 'FOO', 'a should not have changed');
assert.equal(get(b, 'bar'), 'BAR', 'b should not have changed');

connect();

equal(get(a, 'foo'), 'BAR', 'a should have changed');
equal(get(b, 'bar'), 'BAR', 'b should have changed');
assert.equal(get(a, 'foo'), 'BAR', 'a should have changed');
assert.equal(get(b, 'bar'), 'BAR', 'b should have changed');
//
// make sure changes sync both ways
run(() => set(b, 'bar', 'BAZZ'));
equal(get(a, 'foo'), 'BAZZ', 'a should have changed');
assert.equal(get(a, 'foo'), 'BAZZ', 'a should have changed');

run(() => set(a, 'foo', 'BARF'));
equal(get(b, 'bar'), 'BARF', 'a should have changed');
assert.equal(get(b, 'bar'), 'BARF', 'a should have changed');
}

let originalLookup, lookup, GlobalB;

QUnit.module('Ember.Binding', {
setup() {
beforeEach() {
originalLookup = context.lookup;
context.lookup = lookup = {};
},
teardown() {
afterEach() {
lookup = null;
context.lookup = originalLookup;
}
Expand Down Expand Up @@ -76,7 +78,7 @@ testBoth('Connecting a binding between two objects', function(get, set) {
}, /`Ember\.Binding` is deprecated./);
});

testBoth('Connecting a binding to path', function(get, set) {
testBoth('Connecting a binding to path', function(get, set, assert) {
let a = { foo: 'FOO' };
lookup['GlobalB'] = GlobalB = {
b: { bar: 'BAR' }
Expand All @@ -96,7 +98,7 @@ testBoth('Connecting a binding to path', function(get, set) {

run(() => set(GlobalB, 'b', b));

equal(get(a, 'foo'), 'BIFF', 'a should have changed');
assert.equal(get(a, 'foo'), 'BIFF', 'a should have changed');
});

testBoth('Calling connect more than once', function(get, set) {
Expand All @@ -114,7 +116,7 @@ testBoth('Calling connect more than once', function(get, set) {
}, /`Ember\.Binding` is deprecated./);
});

QUnit.test('inherited bindings should sync on create', function() {
QUnit.test('inherited bindings should sync on create', function(assert) {
let a;
run(() => {
function A() {
Expand All @@ -126,5 +128,5 @@ QUnit.test('inherited bindings should sync on create', function() {
set(a, 'bar', { baz: 'BAZ' });
});

equal(get(a, 'foo'), 'BAZ', 'should have synced binding on new obj');
assert.equal(get(a, 'foo'), 'BAZ', 'should have synced binding on new obj');
});
24 changes: 12 additions & 12 deletions packages/ember-metal/tests/binding/sync_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {

QUnit.module('system/binding/sync_test.js');

testBoth('bindings should not sync twice in a single run loop', function(get, set) {
testBoth('bindings should not sync twice in a single run loop', function(get, set, assert) {
let a, b, setValue;
let setCalled = 0;
let getCalled = 0;
Expand Down Expand Up @@ -47,12 +47,12 @@ testBoth('bindings should not sync twice in a single run loop', function(get, se
set(a, 'foo', 'trollface');
});

equal(get(b, 'foo'), 'trollface', 'the binding should sync');
equal(setCalled, 1, 'Set should only be called once');
equal(getCalled, 1, 'Get should only be called once');
assert.equal(get(b, 'foo'), 'trollface', 'the binding should sync');
assert.equal(setCalled, 1, 'Set should only be called once');
assert.equal(getCalled, 1, 'Get should only be called once');
});

testBoth('bindings should not infinite loop if computed properties return objects', function(get) {
testBoth('bindings should not infinite loop if computed properties return objects', function(get, set, assert) {
let a, b;
let getCalled = 0;

Expand All @@ -74,11 +74,11 @@ testBoth('bindings should not infinite loop if computed properties return object
expectDeprecation(() => bind(b, 'foo', 'a.foo'), /`Ember.Binding` is deprecated/);
});

deepEqual(get(b, 'foo'), ['foo', 'bar'], 'the binding should sync');
equal(getCalled, 1, 'Get should only be called once');
assert.deepEqual(get(b, 'foo'), ['foo', 'bar'], 'the binding should sync');
assert.equal(getCalled, 1, 'Get should only be called once');
});

testBoth('bindings should do the right thing when observers trigger bindings in the opposite direction', function(get, set) {
testBoth('bindings should do the right thing when observers trigger bindings in the opposite direction', function(get, set, assert) {
let a, b, c;

run(() => {
Expand Down Expand Up @@ -107,10 +107,10 @@ testBoth('bindings should do the right thing when observers trigger bindings in

run(() => set(a, 'foo', 'trollface'));

equal(get(a, 'foo'), 'what is going on');
assert.equal(get(a, 'foo'), 'what is going on');
});

testBoth('bindings should not try to sync destroyed objects', function(get, set) {
testBoth('bindings should not try to sync destroyed objects', function(get, set, assert) {
let a, b;

run(() => {
Expand All @@ -130,7 +130,7 @@ testBoth('bindings should not try to sync destroyed objects', function(get, set)
run(() => {
set(a, 'foo', 'trollface');
set(b, 'isDestroyed', true);
ok(true, 'should not raise');
assert.ok(true, 'should not raise');
});

run(() => {
Expand All @@ -150,6 +150,6 @@ testBoth('bindings should not try to sync destroyed objects', function(get, set)
run(() => {
set(b, 'foo', 'trollface');
set(a, 'isDestroyed', true);
ok(true, 'should not raise');
assert.ok(true, 'should not raise');
});
});
Loading