adopted-ember-addons / ember-cp-validations

Ember computed property based validations
https://adopted-ember-addons.github.io/ember-cp-validations/
BSD 3-Clause "New" or "Revised" License
441 stars 174 forks source link

hasValidations decorator ES6/TypeScript #603

Open josemarluedke opened 6 years ago

josemarluedke commented 6 years ago

I'm trying to use cp-validations within an app using ES6 classes & TypeScript and I'm getting a few errors.

Here is what my component looks like:

import Component from '@ember/component';
import {
  validator,
  buildValidations,
  hasValidations
} from 'ember-cp-validations';

const Validations = buildValidations({
  identification: [
    validator('presence', true),
    validator('format', { type: 'email' })
  ],

  password: [
    validator('presence', true),
    validator('length', {
      min: 8
    })
  ]
});

@hasValidations(Validations)
export default class LoginForm extends Component.extend({
  // .... 
}) {
  identification: string = '';
  password: string = '';
}

The first problem that I get is when running tests for this component, the error I get is:

Error: Assertion Failed: You must call `this._super(...arguments);` when overriding `init` on a framework object. Please update <maestro@component:login-form::ember238> to call `this._super(...arguments);` from `init`.@ 196 ms

This error only appears in tests, but not when running the app.

Note: Using Component.extend does not work, so I have to use the decorator.

Environment

Steps to Reproduce

https://github.com/josemarluedke/--ember-cp-validations-repro

josemarluedke commented 6 years ago

@offirgolan I have created a reproduction for this bug: https://github.com/josemarluedke/--ember-cp-validations-repro.

One interesting thing I discovered is that if I add an action to the component, then I don't have this problem. I don't have an action in my component since I'm using ember-concurrency tasks.