diff --git a/karma.conf.js b/karma.conf.js index fcca96d4..bb2c0b92 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -24,6 +24,7 @@ module.exports = function(config) { // list of files to exclude exclude: [ + 'dist/test/test/server.js', ], diff --git a/package.json b/package.json index 22851343..22220ae1 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,7 @@ "devDependencies": { "aurelia-bootstrapper": "^2.0.1", "aurelia-pal-browser": "^1.1.0", + "aurelia-pal-nodejs": "^1.0.0-beta.1.0.0", "aurelia-polyfills": "^1.1.1", "aurelia-testing": "^1.0.0-beta.2.0.1", "concurrently": "^3.1.0", diff --git a/src/aurelia-validation.ts b/src/aurelia-validation.ts index e7a9acfd..edf26e43 100644 --- a/src/aurelia-validation.ts +++ b/src/aurelia-validation.ts @@ -54,7 +54,7 @@ export class AureliaValidationConfiguration { * Configures the plugin. */ export function configure( - frameworkConfig: { container: Container, globalResources: (...resources: string[]) => any }, + frameworkConfig: { container: Container, globalResources?: (...resources: string[]) => any }, callback?: (config: AureliaValidationConfiguration) => void ) { // the fluent rule definition API needs the parser to translate messages @@ -70,8 +70,10 @@ export function configure( config.apply(frameworkConfig.container); // globalize the behaviors. - frameworkConfig.globalResources( - './validate-binding-behavior', - './validation-errors-custom-attribute', - './validation-renderer-custom-attribute'); + if (frameworkConfig.globalResources) { + frameworkConfig.globalResources( + './validate-binding-behavior', + './validation-errors-custom-attribute', + './validation-renderer-custom-attribute'); + } } diff --git a/src/validation-errors-custom-attribute.ts b/src/validation-errors-custom-attribute.ts index f584f8b9..2e768462 100644 --- a/src/validation-errors-custom-attribute.ts +++ b/src/validation-errors-custom-attribute.ts @@ -4,6 +4,7 @@ import { customAttribute, bindable } from 'aurelia-templating'; import { ValidationController } from './validation-controller'; import { ValidateResult } from './validate-result'; import { ValidationRenderer, RenderInstruction } from './validation-renderer'; +import { DOM } from 'aurelia-pal'; export interface RenderedError { error: ValidateResult; @@ -12,7 +13,7 @@ export interface RenderedError { @customAttribute('validation-errors') export class ValidationErrorsCustomAttribute implements ValidationRenderer { - public static inject = [Element, Lazy.of(ValidationController)]; + public static inject = [DOM.Element, Lazy.of(ValidationController)]; @bindable({ defaultBindingMode: bindingMode.oneWay }) public controller: ValidationController | null = null; diff --git a/test/server.ts b/test/server.ts new file mode 100644 index 00000000..bb6aec7b --- /dev/null +++ b/test/server.ts @@ -0,0 +1,45 @@ +import 'aurelia-polyfills'; +import {initialize} from 'aurelia-pal-nodejs'; +import {Container} from 'aurelia-dependency-injection'; +import {configure as configureBindingLanguage} from 'aurelia-templating-binding'; +import { + configure as configureValidation, + ValidationRules, + Validator +} from '../src/aurelia-validation'; +import * as assert from 'assert'; + +initialize(); +const container = new Container(); +configureBindingLanguage({ container }); +configureValidation({ container }); + +const rules = ValidationRules + .ensure('firstName').required() + .ensure('lastName').required() + .rules; + +const validator: Validator = container.get(Validator); + +validator.validateObject({ firstName: '', lastName: 'test'}, rules) + .then(result => { + assert(result.length === 2); + assert(result[0].propertyName === 'firstName'); + assert(result[0].valid === false); + assert(result[1].propertyName === 'lastName'); + assert(result[1].valid === true); + }); + +validator.validateProperty({ firstName: '', lastName: 'test'}, 'firstName', rules) + .then(result => { + assert(result.length === 1); + assert(result[0].propertyName === 'firstName'); + assert(result[0].valid === false); + }); + +validator.validateProperty({ firstName: '', lastName: 'test'}, 'lastName', rules) + .then(result => { + assert(result.length === 1); + assert(result[0].propertyName === 'lastName'); + assert(result[0].valid === true); + });