-
-
Notifications
You must be signed in to change notification settings - Fork 130
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
What is the correct way to initialise the validation plugin during unit tests? #377
Comments
try this: import {StageComponent, ComponentTester} from 'aurelia-testing';
import {bootstrap} from 'aurelia-bootstrapper';
describe('something', () => {
let component;
beforeAll(done => {
component = StageComponent.withResources().inView('<div></div>').boundTo({});
component.bootstrap(aurelia => aurelia.use.standardConfiguration().plugin('aurelia-validation'));
component.create(bootstrap).then(done);
});
...
...
afterAll(() => {
component.dispose();
});
}); |
Thanks. Tried that - only with:
If I add a simple test - eg:
It blows up with error:
When I import a model class to test that uses ValidationRules into the Jasmine test - eg:
Then simply adding the import to the Jasmine test
then I still get the error.
No other tests run at all in that scenario. I'm guessing this is a problem with aurelia-bootstrapper-webpack - there are open issues there. But thank you for confirming the correct approach to loading the tester environment. If it's not working, at least that points to where the problem might be. |
@niieani Will this be fixed with the new universal bootstrapper? |
Not by the new bootstrapper, but by the new webpack plugin/loader suite. The fixes for this (including an example test) are already in the experimental skeleton. |
Ok, closing as fixed. My hope is we get all this out by early next week. |
Is it fixed? How the test setup is supposed to look like now? None of the proposed solutions here works for me. I don't even use a webpack. It's in JSPM configuration. Example:
import {ValidationRules} from "aurelia-validation";
export class MyModel {
label: string;
}
ValidationRules
.ensure('label').required()
.on(MyModel);
import {MyModel} from "./my-model";
import {StageComponent} from "aurelia-testing";
import {bootstrap} from "aurelia-bootstrapper";
describe('MyModel', () => {
let component;
beforeAll(done => {
component = StageComponent.withResources().inView('<div></div>').boundTo({});
component.bootstrap(aurelia => aurelia.use.standardConfiguration().plugin('aurelia-validation'));
component.create(bootstrap as any).then(done);
});
afterAll(() => {
component.dispose();
});
it("creates new instance", () => {
let model = new MyModel();
});
}); The output:
|
As a workaround, if the validation rules is not the thing that is going to be tested, one can opt-out them in the code like: export class MyModel {
label: string;
}
if ((ValidationRules as any).parser) {
ValidationRules
.ensure('label').required()
on(MyModel);
} This at least allows the tests that use the model run. |
we really need a complete JSPM example from @fracz first comment. Using JSPM and a view-model (not a custom element) leaves me stranded now that all my tests will not run when aurelia-validation is added to the view-model. i have an open question on stackoverflow. Thank you. |
For what it's worth; I've added a feature request for a stubbed ValidationController over in the aurelia-testing repo (aurelia/testing#63). |
Question.
I am using aurelia with webpack. Current versions of everything.
What is the correct way to initialise the validation plugin during unit tests?
I have tried something like this - setup.js:
But that does not seem to work (maybe I have missed something important).
When I start my tests, I get error:
This may be related to issues with aurelia-bootstrapper-webpack - there are defects raised there.
But I am wondering if there is any other way to make sure the plugin is initialised. This is preventing all unit testing taking place in my app.
The text was updated successfully, but these errors were encountered: