Skip to content

Commit

Permalink
fixed for running e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yoraco committed Aug 16, 2020
1 parent 1d9bb30 commit 8b1f931
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"copy:schema": "node -e \"var src='./schema/ngx-schema-form-schema.json'; var dest='./dist/schema-form/ngx-schema-form-schema.json'; var fs = require('fs'); if (fs.existsSync(src)) { var data = fs.readFileSync(src, 'utf-8'); fs.writeFileSync(dest, data);}\"",
"build:lib": "ng build --prod schema-form && npm run copy:schema && cp ./README.md ./dist/schema-form/",
"build-demo": "ng build --prod --base-href /ngx-schema-form/dist/ngx-schema-form/",
"test": "ng test schema-form --watch=false",
"test:lib": "ng test schema-form --watch=false",
"test": "ng test --watch=false",
"lint": "ng lint",
"get_version": "cat ./projects/schema-form/package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]'"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('JsonSchemaExampleComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
SchemaFormModule,
SchemaFormModule.forRoot(),
HttpClientModule
],
declarations: [ JsonSchemaExampleComponent ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
<div class="row">
<div class="col-md-4">
<h3>Form:</h3>
<sf-form #form [(ngModel)]="model" templateSchema>
<sf-form #form
[(ngModel)]="model"
(onChange)="setValue($event.value)"
templateSchema>
<sf-field name="recipient" type="object">
Part 1 - Recipient
<sf-field
Expand Down Expand Up @@ -302,7 +305,7 @@ <h3>Template:</h3>
</div>
<div class="col-md-4">
<h3>Model:</h3>
<pre>{{model | json}}</pre>
<pre>{{value | json}}</pre>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('TemplateSchemaExampleComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
SchemaFormModule,
SchemaFormModule.forRoot(),
TemplateSchemaModule,
HttpClientModule,
FormsModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { Component, OnInit } from '@angular/core';
export class TemplateSchemaExampleComponent implements OnInit {

model: any = {};
/**
* Using a separate variable for showing the model prevents from:
* `Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value:`
*/
value;

constructor() { }

Expand All @@ -18,4 +23,18 @@ export class TemplateSchemaExampleComponent implements OnInit {
ngOnInit() {
}

setValue(value) {
if (undefined === this.value) {
/**
* If the first time the variable is set, then setting timeout will prevents error:
* `Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value:`
*/
setTimeout(() => {
this.value = value;
}, 0);
return
}
this.value = value;
}

}

0 comments on commit 8b1f931

Please sign in to comment.