Skip to content

Commit

Permalink
upgrade qunit to fix CSP violations in test runner
Browse files Browse the repository at this point in the history
This one requires a migration from deprecated ember-cli-qunit to ember-qunit.
ember-qunit throws in Unit tests cause they interact with runloop but didn't
awaited everything to finish. An assertion was thrown therefor:

> Assertion Failed: expected container not to be destroyed
  • Loading branch information
jelhan committed Feb 23, 2019
1 parent 23754af commit 3246b2d
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 140 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"ember-cli-mirage": "^0.4.10",
"ember-cli-moment-shim": "^3.7.1",
"ember-cli-page-object": "^1.11.0",
"ember-cli-qunit": "^4.3.2",
"ember-cli-release": "^0.2.9",
"ember-cli-sass": "^8.0.1",
"ember-cli-sauce": "^1.6.0",
Expand All @@ -63,6 +62,7 @@
"ember-maybe-import-regenerator": "^0.1.6",
"ember-moment": "^7.8.0",
"ember-page-title": "^5.0.0",
"ember-qunit": "^4.4.0",
"ember-radio-buttons": "^4.0.1",
"ember-resolver": "^5.0.1",
"ember-route-action-helper": "^2.0.6",
Expand Down
99 changes: 47 additions & 52 deletions tests/unit/components/create-options-datetime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { run } from '@ember/runloop';
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import moment from 'moment';
import { settled } from '@ember/test-helpers';

module('Unit | Component | create options datetime', function(hooks) {
setupTest(hooks);
Expand Down Expand Up @@ -153,23 +154,21 @@ module('Unit | Component | create options datetime', function(hooks) {
);
});

test('adopt times of first day - simple', function(assert) {
let component;
let poll;
run(() => {
poll = this.store.createRecord('poll', {
options: [
{ title: moment('2015-01-01T11:11:00.000').toISOString() },
{ title: moment('2015-01-01T22:22:00.000').toISOString() },
{ title: moment('2015-01-02').toISOString() },
{ title: moment('2015-01-03').toISOString() }
]
});
component = this.owner.factoryFor('component:create-options-datetime').create({
dates: poll.get('options')
});
component.send('adoptTimesOfFirstDay');
test('adopt times of first day - simple', async function(assert) {
let poll = this.store.createRecord('poll', {
options: [
{ title: moment('2015-01-01T11:11:00.000').toISOString() },
{ title: moment('2015-01-01T22:22:00.000').toISOString() },
{ title: moment('2015-01-02').toISOString() },
{ title: moment('2015-01-03').toISOString() }
]
});
let component = this.owner.factoryFor('component:create-options-datetime').create({
dates: poll.get('options')
});
component.send('adoptTimesOfFirstDay');
await settled();

assert.deepEqual(
component.get('dates').map((option) => option.get('title')),
[
Expand All @@ -184,27 +183,25 @@ module('Unit | Component | create options datetime', function(hooks) {
);
});

test('adopt times of first day - having times on the other days', function(assert) {
let component;
let poll;
run(() => {
poll = this.store.createRecord('poll', {
options: [
{ title: moment('2015-01-01T11:11:00.000').toISOString() },
{ title: moment('2015-01-01T22:22:00.000').toISOString() },
{ title: moment('2015-01-02T09:11:00.000').toISOString() },
{ title: moment('2015-01-03T01:11:00.000').toISOString() },
{ title: moment('2015-01-03T11:11:00.000').toISOString() },
{ title: moment('2015-01-04T02:11:00.000').toISOString() },
{ title: moment('2015-01-04T05:11:00.000').toISOString() },
{ title: moment('2015-01-04T12:11:00.000').toISOString() }
]
});
component = this.owner.factoryFor('component:create-options-datetime').create({
dates: poll.get('options')
});
component.send('adoptTimesOfFirstDay');
test('adopt times of first day - having times on the other days', async function(assert) {
let poll = this.store.createRecord('poll', {
options: [
{ title: moment('2015-01-01T11:11:00.000').toISOString() },
{ title: moment('2015-01-01T22:22:00.000').toISOString() },
{ title: moment('2015-01-02T09:11:00.000').toISOString() },
{ title: moment('2015-01-03T01:11:00.000').toISOString() },
{ title: moment('2015-01-03T11:11:00.000').toISOString() },
{ title: moment('2015-01-04T02:11:00.000').toISOString() },
{ title: moment('2015-01-04T05:11:00.000').toISOString() },
{ title: moment('2015-01-04T12:11:00.000').toISOString() }
]
});
let component = this.owner.factoryFor('component:create-options-datetime').create({
dates: poll.get('options')
});
component.send('adoptTimesOfFirstDay');
await settled();

assert.deepEqual(
component.get('dates').map((option) => option.get('title')),
[
Expand All @@ -221,23 +218,21 @@ module('Unit | Component | create options datetime', function(hooks) {
);
});

test('adopt times of first day - no times on first day', function(assert) {
let component;
let poll;
run(() => {
poll = this.store.createRecord('poll', {
options: [
{ title: '2015-01-01' },
{ title: '2015-01-02' },
{ title: moment('2015-01-03T11:00:00.000Z').toISOString() },
{ title: moment('2015-01-03T15:00:00.000Z').toISOString() }
]
});
component = this.owner.factoryFor('component:create-options-datetime').create({
dates: poll.get('options')
});
component.send('adoptTimesOfFirstDay');
test('adopt times of first day - no times on first day', async function(assert) {
let poll = this.store.createRecord('poll', {
options: [
{ title: '2015-01-01' },
{ title: '2015-01-02' },
{ title: moment('2015-01-03T11:00:00.000Z').toISOString() },
{ title: moment('2015-01-03T15:00:00.000Z').toISOString() }
]
});
let component = this.owner.factoryFor('component:create-options-datetime').create({
dates: poll.get('options')
});
component.send('adoptTimesOfFirstDay');
await settled();

assert.deepEqual(
component.get('dates').map((option) => option.get('title')),
[
Expand Down
Loading

0 comments on commit 3246b2d

Please sign in to comment.