Skip to content

Instantly share code, notes, and snippets.

@Gaurav0
Last active March 2, 2020 21:00
Show Gist options
  • Save Gaurav0/3597bed7f7b5642fd6a9ac390537281f to your computer and use it in GitHub Desktop.
Save Gaurav0/3597bed7f7b5642fd6a9ac390537281f to your computer and use it in GitHub Desktop.
RFC-232 Tests
import Ember from 'ember';
export default Ember.Component.extend({
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit, currentURL } from '@ember/test-helpers';
module('TODO: put something here', function(hooks) {
setupApplicationTest(hooks);
test('visiting /', async function(assert) {
await visit('/');
assert.equal(currentURL(), '/');
});
});
import { run } from '@ember/runloop';
export default function destroyApp(application) {
run(application, 'destroy');
}
import { module } from 'qunit';
import { resolve } from 'rsvp';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
export default function(name, options = {}) {
module(name, {
beforeEach() {
this.application = startApp();
if (options.beforeEach) {
return options.beforeEach.apply(this, arguments);
}
},
afterEach() {
let afterEach = options.afterEach && options.afterEach.apply(this, arguments);
return resolve(afterEach).then(() => destroyApp(this.application));
}
});
}
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes.autoboot = true;
attributes.rootElement = '#ember-testing';
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import { module, test } from 'qunit';
import { render } from '@ember/test-helpers';
import { setupRenderingTest } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
module('my-component', 'TODO: put something here', function(hooks) {
setupRenderingTest(hooks);
test('it renders', async function(assert) {
await render(hbs`{{my-component}}`);
assert.equal(this.element.textContent.trim(), '');
// Template block usage:
await render(hbs`
{{#my-component}}
template block text
{{/my-component}}
`);
assert.equal(this.element.textContent.trim(), 'template block text');
});
});
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';
setApplication(Application.create(assign({ rootElement: '#test-root', autoboot: false }, config.APP)));
start();
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('controller:application', 'TODO: put something here', function(hooks) {
setupTest(hooks);
test('it exists', function(assert) {
let controller = this.owner.lookup('controller:application');
assert.ok(controller);
});
});
{
"version": "0.16.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": true
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.14.3",
"ember-template-compiler": "3.14.3",
"ember-testing": "3.14.3"
},
"addons": {
"ember-data": "3.14.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment