@mikoscz
Michał Staśkiewicz
moduleFor()
moduleForModel()
moduleForComponent()
moduleForAcceptance()
andThen()
andThen()
andThen()
andThen()
import { test } from 'qunit';
import moduleForAcceptance from 'some-app/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | users');
test('should add new uesr', function(assert) {
visit('/users/new');
fillIn('input.email', 'm.staskiewicz@selleo.com');
click('button.submit');
andThen(() => assert.equal(find('ul.users li:first').text(), 'm.staskiewicz@selleo.com'));
});
import { test } from 'qunit';
import moduleForAcceptance from 'some-app/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | users');
test('should add new uesr', async function(assert) {
await visit('/users/new');
await fillIn('input.email', 'm.staskiewicz@selleo.com');
await click('button.submit');
assert.equal(find('ul.users li:first').text(), 'm.staskiewicz@selleo.com');
});
import { test } from 'qunit';
import moduleForAcceptance from 'some-app/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | users');
test('should add new uesr', async function(assert) {
await visit('/users/new');
await fillIn('input.email', 'm.staskiewicz@selleo.com');
await click('button.submit');
assert.equal(find('ul.users li:first').text(), 'm.staskiewicz@selleo.com');
});
await click('button.submit');
assert.equal(find('ul.users li:first').text(), 'm.staskiewicz@selleo.com');
import { click, find } from 'ember-native-dom-helpers';
await click('button.submit');
assert.equal(find('ul.users li:first').textContent, 'm.staskiewicz@selleo.com');
module()
setupTest()
setupRenderingTest()
// old
moduleForAcceptance()
// new
module()
setupAcceptanceTest()
import { module, test } from 'qunit';
module('relativeDate', function(hooks) {
test('format relative dates correctly', function() {
assert.equal(relativeDate('2018/03/25 19:40:10'), 'just now');
});
});
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Service | events-counter', function(hooks) {
setupTest(hooks);
test('it counts events', function(assert) {
const service = this.owner.lookup('service:events-counter');
service.addEvent('first');
service.addEvent('second');
assert.equal(service.get('eventsCount'), 2);
});
});
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, click } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
module('Component | counter', function(hooks) {
setupRenderingTest(hooks);
test('it counts clicks', async function(assert) {
this.set('count', 0);
await render(hbs`{{click-counter value=value ...}}`);
assert.equal(this.element.textContent, '0 clicks');
await click('.counter');
assert.equal(this.element.textContent, '1 clicks');
});
});
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit, fillIn, click } from '@ember/test-helpers';
module('Acceptance | users', function(hooks) {
setupApplicationTest(hooks);
test('should add new user', async function(assert) {
await visit('/users/new');
await fillIn('input.email', 'm.staskiewicz@selleo.com');
await click('button.submit');
const email = this.element.querySelector('ul.users li:first').textContent;
assert.equal(email, 'm.staskiewicz@selleo.com');
});
});
ember install
ember-cli-qunit 4.2.0 <
test('shows loading spinner after submitting', async function(assert) {
await visit('/comments/new');
await fillIn('input.comment', 'Hello there');
const promise = click('.submit');
await waitFor('.loading-spinner');
assert.ok(find('.spinner'));
await promise;
assert.ok(find('.some-success-notify'));
});
export async function createAccount(email) {
await fillIn('#email', email);
await click('button.submit');
}
// template.hbs
<h1>{{title}}</h1>
<input class="title-field">
// test.js
await fillIn('.title-field', 'Hello from field');
const title = this.element.querySelector('h1').textContent;
assert.equal(title, 'Hello from field');
// template.hbs
<h1 data-test-title>{{title}}</h1>
<input class="title-field" data-test-title-field>
// test.js
await fillIn('[data-test-title-field]', 'Hello from field');
const title = this.element.querySelector('[data-test-title').textContent;
assert.equal(title, 'Hello from field');
const title = this.element.querySelector('[data-test-title').textContent;
assert.equal(title, 'Hello from field');
assert.dom('[data-test-title]').hasText('Hello from field');
assert.dom('h1').exists();
assert.dom('h1').hasClass('title');
assert.dom('h1').hasText('Welcome to Ember, John Doe!');
assert.dom('input').isFocused();
assert.dom('input').hasValue(/.+ Doe/);
assert.dom('input').hasAttribute('type', 'text');