-
-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic implementation of new ember-qunit API. #286
Changes from 1 commit
a65f4e5
e19ad75
9cc8f47
86ce3c0
9ff5188
a197737
b9db3fd
0aa4689
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,42 @@ export { default as moduleFor } from './legacy-2-x/module-for'; | |
export { default as moduleForComponent } from './legacy-2-x/module-for-component'; | ||
export { default as moduleForModel } from './legacy-2-x/module-for-model'; | ||
export { default as QUnitAdapter } from './adapter'; | ||
export { setResolver } from 'ember-test-helpers'; | ||
export { setResolver, render, clearRender, settled } from 'ember-test-helpers'; | ||
export { module, test, skip, only, todo } from 'qunit'; | ||
export { loadTests } from './test-loader'; | ||
|
||
import { loadTests } from './test-loader'; | ||
import Ember from 'ember'; | ||
import QUnit from 'qunit'; | ||
import QUnitAdapter from './adapter'; | ||
import { | ||
setupContext, | ||
teardownContext, | ||
setupRenderingContext, | ||
teardownRenderingContext, | ||
} from 'ember-test-helpers'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplicate import? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, no. The other one is an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, right... |
||
|
||
export function setupTest(hooks, options) { | ||
hooks.beforeEach(function() { | ||
setupContext(this, options); | ||
}); | ||
|
||
hooks.afterEach(function() { | ||
teardownContext(this); | ||
}); | ||
} | ||
|
||
export function setupRenderingTest(hooks, options) { | ||
setupTest(hooks, options); | ||
|
||
hooks.beforeEach(function() { | ||
setupRenderingContext(this); | ||
}); | ||
|
||
hooks.afterEach(function() { | ||
teardownRenderingContext(this); | ||
}); | ||
} | ||
|
||
/** | ||
Uses current URL configuration to setup the test container. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { module, test } from 'qunit'; | ||
import Component from '@ember/component'; | ||
import { helper } from '@ember/component/helper'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import { setupRenderingTest, render } from 'ember-qunit'; | ||
import { setResolverRegistry } from '../helpers/resolver'; | ||
|
||
module('setupRenderingTest tests', function(hooks) { | ||
hooks.beforeEach(function() { | ||
setResolverRegistry({}); | ||
}); | ||
|
||
setupRenderingTest(hooks); | ||
|
||
test('can render a simple template', async function(assert) { | ||
await render(hbs`<p>Hello!</p>`); | ||
|
||
assert.equal(this.element.textContent, 'Hello!'); | ||
}); | ||
|
||
test('can invoke template only components', async function(assert) { | ||
this.owner.register('template:components/template-only', hbs`template-only component here`); | ||
await render(hbs`{{template-only}}`); | ||
|
||
assert.equal(this.element.textContent, 'template-only component here'); | ||
}); | ||
|
||
test('can invoke JS only components', async function(assert) { | ||
this.owner.register( | ||
'component:js-only', | ||
Component.extend({ | ||
classNames: ['js-only'], | ||
}) | ||
); | ||
|
||
await render(hbs`{{js-only}}`); | ||
|
||
assert.ok(this.element.querySelector('.js-only'), 'element found for js-only component'); | ||
}); | ||
|
||
test('can invoke helper', async function(assert) { | ||
this.owner.register('helper:jax', helper(([name]) => `${name}-jax`)); | ||
|
||
await render(hbs`{{jax "max"}}`); | ||
|
||
assert.equal(this.element.textContent, 'max-jax'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { module, test } from 'qunit'; | ||
import Service, { inject as injectService } from '@ember/service'; | ||
import Component from '@ember/component'; | ||
import { setupTest } from 'ember-qunit'; | ||
import hasEmberVersion from 'ember-test-helpers/has-ember-version'; | ||
import { setResolverRegistry } from '../helpers/resolver'; | ||
|
||
module('setupTest tests', function(hooks) { | ||
hooks.beforeEach(function() { | ||
setResolverRegistry({}); | ||
}); | ||
|
||
setupTest(hooks); | ||
|
||
test('can be used for unit style testing', function(assert) { | ||
this.owner.register( | ||
'service:foo', | ||
Service.extend({ | ||
someMethod() { | ||
return 'hello thar!'; | ||
}, | ||
}) | ||
); | ||
|
||
let subject = this.owner.lookup('service:foo'); | ||
|
||
assert.equal(subject.someMethod(), 'hello thar!'); | ||
}); | ||
|
||
test('can access a shared service instance', function(assert) { | ||
this.owner.register('service:bar', Service.extend()); | ||
this.owner.register( | ||
'service:foo', | ||
Service.extend({ | ||
bar: injectService(), | ||
someMethod() { | ||
this.set('bar.someProp', 'derp'); | ||
}, | ||
}) | ||
); | ||
|
||
let subject = this.owner.lookup('service:foo'); | ||
let bar = this.owner.lookup('service:bar'); | ||
|
||
assert.notOk(bar.get('someProp'), 'precond - initially undefined'); | ||
|
||
subject.someMethod(); | ||
|
||
assert.equal(bar.get('someProp'), 'derp', 'property updated'); | ||
}); | ||
|
||
test('can create a component instance for direct testing without a template', function(assert) { | ||
this.owner.register( | ||
'component:foo-bar', | ||
Component.extend({ | ||
someMethod() { | ||
return 'hello thar!'; | ||
}, | ||
}) | ||
); | ||
|
||
let subject; | ||
if (hasEmberVersion(2, 12)) { | ||
subject = this.owner.lookup('component:foo-bar'); | ||
} else { | ||
subject = this.owner._lookupFactory('component:foo-bar').create(); | ||
} | ||
|
||
assert.equal(subject.someMethod(), 'hello thar!'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how did that ever work?! 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NO CLUE!?!?!?