Support for new test syntax
See original GitHub issueHas anyone got integration tests working for their (lazy) engine, with the new test syntax?
I get the error that xxxx is not a helper
. I guess it is because setApplication
sets the dummy app, in which the components themselves are not directly registered?
I somehow got it to work with this pretty hacky code:
import Resolver from '../../resolver';
import { setResolver } from '@ember/test-helpers';
const modulePrefix = 'my-engine-name';
const resolver = Resolver.create();
export default function setupResolver(hooks) {
// Manually fix the entries for the engines so they can be found by the resolver
// Put everything from the my-engine-name namespace into dummy as well
// E.g. my-engine-name/components/my-component becomes dummy/components/my-component
let modules = resolver._moduleRegistry._entries;
let newModules = {};
let overwriteModules = {};
let originalModules = {};
Object.keys(modules).forEach((module) => {
if (module.startsWith(modulePrefix)) {
let newName = `dummy/${module.substr(modulePrefix.length + 1)}`;
if (!modules[newName]) {
newModules[newName] = modules[module];
} else {
originalModules[newName] = modules[module];
overwriteModules[newName] = modules[module];
}
}
});
hooks.beforeEach(function() {
Object.keys(newModules).forEach((module) => {
modules[module] = newModules[module];
});
Object.keys(overwriteModules).forEach((module) => {
modules[module] = overwriteModules[module];
});
});
hooks.afterEach(function() {
Object.keys(newModules).forEach((module) => {
delete modules[module];
});
Object.keys(overwriteModules).forEach((module) => {
modules[module] = originalModules[module];
});
});
return setResolver(resolver);
}
and then, in my integration tests:
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import setResolver from 'dummy/tests/helpers/set-resolver';
// ... other dependencies
module('Integration | Component | my test component', function(hooks) {
setupRenderingTest(hooks);
setResolver(hooks);
// actual tests go here
});
I’m sure there is a better way, but I’m not sure what it is 😉
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:12 (9 by maintainers)
Top Results From Across the Web
test — Regression tests package for Python — Python 3.11.1 ...
The test package contains all regression tests for Python as well as the modules test.support and test.regrtest. test.support is used to enhance your...
Read more >Testing - Spring
This chapter covers Spring's support for integration testing and best practices for unit testing. The Spring team advocates test-driven ...
Read more >New-Service (Microsoft.PowerShell.Management)
The New-Service cmdlet creates a new entry for a Windows service in the registry ... Service" StartupType = "Manual" Description = "This is...
Read more >Writing and Organizing Tests - Cypress Documentation
What you'll learn How to organize your test and support files. ... After adding a new project, Cypress will automatically scaffold out a...
Read more >BDD test syntax | Developer Guide - Nightwatch.js
test() / it() / specify(); before(); after(); beforeEach(); afterEach(). Nightwatch doesn't support ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was just about to paste this code based on the ember-asset-loader README:
Didn’t know that this is a promise, thanks!
For the impatient Googler, the correct code is:
Once we upgraded Ember Data and Ember.js to 3.16, using
setupTest(hooks, { resolver });
approach in engine unit/rendering tests results in deprecation message being triggered by Ember Data:triggered from here https://github.com/emberjs/data/blob/85dbc55e7989157307ab897ac0b126bd777a724b/packages/-ember-data/addon/setup-container.js#L13
Looking into what happens when
resolver
is provided tosetupTest
, looks like it casesbuildOwner
function to uselegacyBuildRegistry
function:https://github.com/emberjs/ember-test-helpers/blob/master/addon-test-support/%40ember/test-helpers/setup-context.ts#L197 https://github.com/emberjs/ember-test-helpers/blob/master/addon-test-support/%40ember/test-helpers/build-owner.ts#L54
Looks like with new Ember versions using the approach suggested in above comment is not gonna work moving forward and we need to find a new solution that would work with New Testing Style helpers (which should happen with #653).