Skip to content

Commit

Permalink
fix(examples): shallow copy initial data to make tests independent
Browse files Browse the repository at this point in the history
  • Loading branch information
tomastrajan committed Jun 25, 2019
1 parent 010080a commit e3280cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ describe('UserService', () => {

it('should add user', done => {
service.addUser({ username: 'test', name: 'Test', surname: 'Tester' });
setTimeout(() => {
service.users$.subscribe(users => {
expect(users.length).toBe(4);
done();
});
service.users$.subscribe(users => {
expect(users.length).toBe(4);
expect(users[3].username).toBe('test');
done();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
import { Model, ModelFactory } from '@angular-extensions/model';
import { Observable } from 'rxjs';

const initialData: User[] = [
const INITIAL_DATA: User[] = [
{ id: uuid(), username: 'rockets', name: 'Elon', surname: 'Musk' },
{ id: uuid(), username: 'investing', name: 'Nassim', surname: 'Taleb' },
{ id: uuid(), username: 'philosophy', name: 'Yuval', surname: 'Harari' }
Expand All @@ -16,7 +16,7 @@ export class UserService {
users$: Observable<User[]>;

constructor(private modelFactory: ModelFactory<User[]>) {
this.model = this.modelFactory.create(initialData);
this.model = this.modelFactory.create([...INITIAL_DATA]);
this.users$ = this.model.data$;
}

Expand Down

0 comments on commit e3280cd

Please sign in to comment.