Skip to content

Commit

Permalink
Silence warnings and deprecations in the console durring tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bmac committed Nov 18, 2016
1 parent c16ae77 commit 3d49afe
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 69 deletions.
2 changes: 1 addition & 1 deletion tests/helpers/setup-ember-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Ember from 'ember';
import EmberTestHelpers from "ember-dev/test-helper/index";

const AVAILABLE_ASSERTIONS = ['expectAssertion', 'expectDeprecation', 'expectNoDeprecation', 'expectWarning', 'expectNoWarning'];
const AVAILABLE_ASSERTIONS = ['expectAssertion', 'expectDeprecation', 'expectNoDeprecation', 'expectWarning', 'expectNoWarning', 'ignoreDeprecation'];

// Maintain backwards compatiblity with older versions of ember.
var emberDebugModule;
Expand Down
16 changes: 10 additions & 6 deletions tests/integration/adapter/rest-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1349,17 +1349,21 @@ test("queryRecord - returning sideloaded data loads the data", function(assert)
}));
});

test("queryRecord - returning an array picks the first one but saves all records to the store", function(assert) {
testInDebug("queryRecord - returning an array picks the first one but saves all records to the store", function(assert) {
ajaxResponse({
post: [{ id: 1, name: "Rails is omakase" }, { id: 2, name: "Ember is js" }]
});

store.queryRecord('post', { slug: 'rails-is-omakaze' }).then(assert.wait(function(post) {
var post2 = store.peekRecord('post', 2);
assert.expectDeprecation('The adapter returned an array for the primary data of a `queryRecord` response. This is deprecated as `queryRecord` should return a single record.');

assert.deepEqual(post.getProperties('id', 'name'), { id: "1", name: "Rails is omakase" });
assert.deepEqual(post2.getProperties('id', 'name'), { id: "2", name: "Ember is js" });
}));
run(function() {
store.queryRecord('post', { slug: 'rails-is-omakaze' }).then(assert.wait(function(post) {
var post2 = store.peekRecord('post', 2);

assert.deepEqual(post.getProperties('id', 'name'), { id: "1", name: "Rails is omakase" });
assert.deepEqual(post2.getProperties('id', 'name'), { id: "2", name: "Ember is js" });
}));
});
});

testInDebug("queryRecord - returning an array is deprecated", function(assert) {
Expand Down
44 changes: 26 additions & 18 deletions tests/integration/records/error-test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import Ember from 'ember';
import {module, test} from 'qunit';
import {module} from 'qunit';
import DS from 'ember-data';
import setupStore from 'dummy/tests/helpers/store';
import testInDebug from 'dummy/tests/helpers/test-in-debug';

var env, store, Person;
var attr = DS.attr;
var run = Ember.run;

function updateErrors(func) {
window.expectWarning(function() {
run(func);
}, 'Interacting with a record errors object will no longer change the record state.');
}

module('integration/records/error', {
beforeEach: function() {
Person = DS.Model.extend({
Expand All @@ -28,8 +35,8 @@ module('integration/records/error', {
}
});

test('adding errors during root.loaded.created.invalid works', function(assert) {
assert.expect(3);
testInDebug('adding errors during root.loaded.created.invalid works', function(assert) {
assert.expect(5);

var person = run(() => {
store.push({
Expand All @@ -51,11 +58,12 @@ test('adding errors during root.loaded.created.invalid works', function(assert)
});

assert.equal(person._internalModel.currentState.stateName, 'root.loaded.updated.uncommitted');
Ember.run(() => person.get('errors').add('firstName', 'is invalid') );

updateErrors(() => person.get('errors').add('firstName', 'is invalid') , assert);

assert.equal(person._internalModel.currentState.stateName, 'root.loaded.updated.invalid');

Ember.run(() => person.get('errors').add('lastName', 'is invalid') );
updateErrors(() => person.get('errors').add('lastName', 'is invalid'), assert);

assert.deepEqual(person.get('errors').toArray(), [
{ attribute: 'firstName', message: 'is invalid' },
Expand All @@ -64,8 +72,8 @@ test('adding errors during root.loaded.created.invalid works', function(assert)
});


test('adding errors root.loaded.created.invalid works', function(assert) {
assert.expect(3);
testInDebug('adding errors root.loaded.created.invalid works', function(assert) {
assert.expect(5);

var person = run(() => {
return store.createRecord('person', {
Expand All @@ -82,20 +90,20 @@ test('adding errors root.loaded.created.invalid works', function(assert) {

assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.uncommitted');

Ember.run(() => person.get('errors').add('firstName', 'is invalid') );
updateErrors(() => person.get('errors').add('firstName', 'is invalid') );

assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.invalid');

Ember.run(() => person.get('errors').add('lastName', 'is invalid') );
updateErrors(() => person.get('errors').add('lastName', 'is invalid') );

assert.deepEqual(person.get('errors').toArray(), [
{ attribute: 'firstName', message: 'is invalid' },
{ attribute: 'lastName', message: 'is invalid' }
]);
});

test('adding errors root.loaded.created.invalid works add + remove + add', function(assert) {
assert.expect(4);
testInDebug('adding errors root.loaded.created.invalid works add + remove + add', function(assert) {
assert.expect(7);

var person = run(() => {
return store.createRecord('person', {
Expand All @@ -110,23 +118,23 @@ test('adding errors root.loaded.created.invalid works add + remove + add', funct

assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.uncommitted');

Ember.run(() => person.get('errors').add('firstName', 'is invalid') );
updateErrors(() => person.get('errors').add('firstName', 'is invalid') );

assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.invalid');

Ember.run(() => person.get('errors').remove('firstName'));
updateErrors(() => person.get('errors').remove('firstName'));

assert.deepEqual(person.get('errors').toArray(), []);

Ember.run(() => person.get('errors').add('firstName', 'is invalid') );
updateErrors(() => person.get('errors').add('firstName', 'is invalid') );

assert.deepEqual(person.get('errors').toArray(), [
{ attribute: 'firstName', message: 'is invalid' }
]);
});

test('adding errors root.loaded.created.invalid works add + (remove, add)', function(assert) {
assert.expect(4);
testInDebug('adding errors root.loaded.created.invalid works add + (remove, add)', function(assert) {
assert.expect(6);

var person = run(() => {
return store.createRecord('person', {
Expand All @@ -141,13 +149,13 @@ test('adding errors root.loaded.created.invalid works add + (remove, add)', func

assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.uncommitted');

Ember.run(() => {
updateErrors(() => {
person.get('errors').add('firstName', 'is invalid');
});

assert.equal(person._internalModel.currentState.stateName, 'root.loaded.created.invalid');

Ember.run(() => {
updateErrors(() => {
person.get('errors').remove('firstName');
person.get('errors').add('firstName', 'is invalid');
});
Expand Down
9 changes: 5 additions & 4 deletions tests/integration/serializers/json-serializer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ test('normalizeResponse respects `included` items (array response)', function(as
]);
});

test('normalizeResponse ignores unmapped attributes', function(assert) {
testInDebug('normalizeResponse ignores unmapped attributes', function(assert) {
env.registry.register("serializer:post", DS.JSONSerializer.extend({
attrs: {
title: { serialize: false },
Expand All @@ -987,9 +987,10 @@ test('normalizeResponse ignores unmapped attributes', function(assert) {
title: "Rails is omakase"
};

var post = env.store.serializerFor("post").normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord');

assert.equal(post.data.attributes.title, "Rails is omakase");
assert.expectWarning(function() {
var post = env.store.serializerFor("post").normalizeResponse(env.store, Post, jsonHash, '1', 'findRecord');
assert.equal(post.data.attributes.title, "Rails is omakase");
}, /There is no attribute or relationship with the name/);
});

test('options are passed to transform for serialization', function(assert) {
Expand Down
61 changes: 33 additions & 28 deletions tests/unit/model/errors-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import DS from 'ember-data';
import QUnit, {module, test} from 'qunit';
import QUnit, {module} from 'qunit';
import testInDebug from 'dummy/tests/helpers/test-in-debug';

const AssertPrototype = QUnit.assert;

Expand All @@ -14,6 +15,10 @@ module("unit/model/errors", {
}
});

function updateErrors(func) {
window.expectWarning(func, 'Interacting with a record errors object will no longer change the record state.');
}

AssertPrototype.becameInvalid = function becameInvalid(eventName) {
if (eventName === 'becameInvalid') {
this.ok(true, 'becameInvalid send');
Expand All @@ -34,32 +39,32 @@ AssertPrototype.unexpectedSend = function unexpectedSend(eventName) {
this.ok(false, 'unexpected send : ' + eventName);
}.bind(AssertPrototype);

test("add error", function(assert) {
assert.expect(6);
testInDebug("add error", function(assert) {
assert.expect(10);
errors.trigger = assert.becameInvalid;
errors.add('firstName', 'error');
updateErrors(() => errors.add('firstName', 'error'));
errors.trigger = assert.unexpectedSend;
assert.ok(errors.has('firstName'), 'it has firstName errors');
assert.equal(errors.get('length'), 1, 'it has 1 error');
errors.add('firstName', ['error1', 'error2']);
updateErrors(() => errors.add('firstName', ['error1', 'error2']));
assert.equal(errors.get('length'), 3, 'it has 3 errors');
assert.ok(!errors.get('isEmpty'), 'it is not empty');
errors.add('lastName', 'error');
errors.add('lastName', 'error');
updateErrors(() => errors.add('lastName', 'error'));
updateErrors(() => errors.add('lastName', 'error'));
assert.equal(errors.get('length'), 4, 'it has 4 errors');
});

test("get error", function(assert) {
assert.expect(8);
testInDebug("get error", function(assert) {
assert.expect(11);
assert.ok(errors.get('firstObject') === undefined, 'returns undefined');
errors.trigger = assert.becameInvalid;
errors.add('firstName', 'error');
updateErrors(() => errors.add('firstName', 'error'));
errors.trigger = assert.unexpectedSend;
assert.ok(errors.get('firstName').length === 1, 'returns errors');
assert.deepEqual(errors.get('firstObject'), { attribute: 'firstName', message: 'error' });
errors.add('firstName', 'error2');
updateErrors(() => errors.add('firstName', 'error2'));
assert.ok(errors.get('firstName').length === 2, 'returns errors');
errors.add('lastName', 'error3');
updateErrors(() => errors.add('lastName', 'error3'));
assert.deepEqual(errors.toArray(), [
{ attribute: 'firstName', message: 'error' },
{ attribute: 'firstName', message: 'error2' },
Expand All @@ -72,42 +77,42 @@ test("get error", function(assert) {
assert.deepEqual(errors.get('messages'), ['error', 'error2', 'error3']);
});

test("remove error", function(assert) {
assert.expect(5);
testInDebug("remove error", function(assert) {
assert.expect(8);
errors.trigger = assert.becameInvalid;
errors.add('firstName', 'error');
updateErrors(() => errors.add('firstName', 'error'));
errors.trigger = assert.becameValid;
errors.remove('firstName');
updateErrors(() => errors.remove('firstName'));
errors.trigger = assert.unexpectedSend;
assert.ok(!errors.has('firstName'), 'it has no firstName errors');
assert.equal(errors.get('length'), 0, 'it has 0 error');
assert.ok(errors.get('isEmpty'), 'it is empty');
errors.remove('firstName');
updateErrors(() => errors.remove('firstName'));
});

test("remove same errors from different attributes", function(assert) {
assert.expect(5);
testInDebug("remove same errors from different attributes", function(assert) {
assert.expect(9);
errors.trigger = assert.becameInvalid;
errors.add('firstName', 'error');
errors.add('lastName', 'error');
updateErrors(() => errors.add('firstName', 'error'));
updateErrors(() => errors.add('lastName', 'error'));
errors.trigger = assert.unexpectedSend;
assert.equal(errors.get('length'), 2, 'it has 2 error');
errors.remove('firstName');
updateErrors(() => errors.remove('firstName'));
assert.equal(errors.get('length'), 1, 'it has 1 error');
errors.trigger = assert.becameValid;
errors.remove('lastName');
updateErrors(() => errors.remove('lastName'));
assert.ok(errors.get('isEmpty'), 'it is empty');
});

test("clear errors", function(assert) {
assert.expect(5);
testInDebug("clear errors", function(assert) {
assert.expect(8);
errors.trigger = assert.becameInvalid;
errors.add('firstName', ['error', 'error1']);
updateErrors(() => errors.add('firstName', ['error', 'error1']));
assert.equal(errors.get('length'), 2, 'it has 2 errors');
errors.trigger = assert.becameValid;
errors.clear();
updateErrors(() => errors.clear());
errors.trigger = assert.unexpectedSend;
assert.ok(!errors.has('firstName'), 'it has no firstName errors');
assert.equal(errors.get('length'), 0, 'it has 0 error');
errors.clear();
updateErrors(() => errors.clear());
});
26 changes: 14 additions & 12 deletions tests/unit/store/adapter-interop-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,8 @@ test("the promise returned by `_scheduleFetch`, when it rejects, does not depend
});
});

test("store._fetchRecord reject records that were not found, even when those requests were coalesced with records that were found", function(assert) {
assert.expect(2);
testInDebug("store._fetchRecord reject records that were not found, even when those requests were coalesced with records that were found", function(assert) {
assert.expect(3);

var Person = DS.Model.extend();

Expand All @@ -859,18 +859,20 @@ test("store._fetchRecord reject records that were not found, even when those req
test: Person
});

run(function () {
var davidPromise = store.findRecord('test', 'david');
var igorPromise = store.findRecord('test', 'igor');
assert.expectWarning(function() {
run(function () {
var davidPromise = store.findRecord('test', 'david');
var igorPromise = store.findRecord('test', 'igor');

davidPromise.then(assert.wait(function () {
assert.ok(true, "David resolved");
}));
davidPromise.then(function () {
assert.ok(true, "David resolved");
});

igorPromise.then(null, assert.wait(function () {
assert.ok(true, "Igor rejected");
}));
});
igorPromise.then(null, function () {
assert.ok(true, "Igor rejected");
});
});
}, /expected to find records with the following ids/);
});

testInDebug("store._fetchRecord warns when records are missing", function(assert) {
Expand Down

0 comments on commit 3d49afe

Please sign in to comment.