Skip to content

Instantly share code, notes, and snippets.

@lolmaus
Last active August 3, 2021 15:28
Show Gist options
  • Save lolmaus/29fdce356f214a97730791b20f28bccd to your computer and use it in GitHub Desktop.
Save lolmaus/29fdce356f214a97730791b20f28bccd to your computer and use it in GitHub Desktop.
Ember Conucrrency perform helper vs Qunit
import Controller from '@ember/controller';
import { task } from 'ember-concurrency';
import { waitFor } from '@ember/test-waiters';
export default class ApplicationController extends Controller {
appName = 'Ember Twiddle';
@waitFor
reject() {
return new Promise((resolve, reject) => reject(new Error('SHOOP DA WHOOP!')));
}
@task
*submitTask() {
return yield this.reject();
}
}
<h1>Welcome to {{this.appName}}</h1>
{{#if this.submitTask.isLoading}}
<p id="loading">
Loading...
</p>
{{else if this.submitTask.last.isError}}
<p id="error">
Something wrong happened:
{{this.submitTask.last.error.message}}
</p>
{{/if}}
<button
{{on "click" (perform this.submitTask)}}
>
Submit
</button>
import { module, test } from 'qunit';
import { visit, currentURL, click, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { setupOnerror, resetOnerror } from '@ember/test-helpers';
module('TODO: put something here', function(hooks) {
setupApplicationTest(hooks);
hooks.beforeEach(() => {
setupOnerror((error) => {});
});
hooks.afterEach(() => {
resetOnerror();
});
test('QUnit and a rejected promise', async function(assert) {
await visit('/');
await click('button');
assert.ok(find('#error'));
});
});
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { assign } from '@ember/polyfills';
import { start } from 'ember-qunit';
let attributes = {
rootElement: '#test-root',
autoboot: false
};
attributes = assign(attributes, config.APP);
let application = Application.create(attributes);
setApplication(application);
start();
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": true
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0",
"ember-concurrency": "2.1.2",
"@ember/test-helpers": "2.3.0",
"@ember/test-waiters": "2.4.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment